ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2025-11-21 07:35:34
Exec Total Coverage
Lines: 2001 4584 43.7%
Functions: 128 335 38.2%
Branches: 1349 3786 35.6%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro/gui.h"
5 #include "allegro/inline/draw.inl"
6 #include "allegro5/joystick.h"
7 #include "base/files.h"
8 #include "base/render.h"
9 #include "base/zdefs.h"
10 #include "zalleg/zalleg.h"
11 #include "base/qrs.h"
12 #include "base/dmap.h"
13 #include <functional>
14 #include <queue>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <cstring>
18 #include <math.h>
19 #include <map>
20 #include <filesystem>
21 #include <ctype.h>
22 #include <sstream>
23 #include "base/version.h"
24 #include "base/zc_alleg.h"
25 #include "gamedata.h"
26 #include "zc/frame_timings.h"
27 #include "zc/replay_upload.h"
28 #include "zc/zasm_pipeline.h"
29 #include "zc/zc_init.h"
30 #include "init.h"
31 #include "zc/replay.h"
32 #include "zc/cheats.h"
33 #include "zc/render.h"
34 #include "base/zc_math.h"
35 #include "base/zapp.h"
36 #include "dialog/cheatkeys.h"
37 #include "metadata/metadata.h"
38 #include "zc/zelda.h"
39 #include "zc/saves.h"
40 #include "tiles.h"
41 #include "base/colors.h"
42 #include "pal.h"
43 #include "base/zsys.h"
44 #include "base/qst.h"
45 #include "zc/zc_sys.h"
46 #include "play_midi.h"
47 #include "gui/jwin_a5.h"
48 #include "base/jwinfsel.h"
49 #include "base/gui.h"
50 #include "midi.h"
51 #include "subscr.h"
52 #include "zc/maps.h"
53 #include "sprite.h"
54 #include "zc/guys.h"
55 #include "zc/hero.h"
56 #include "zc/title.h"
57 #include "particles.h"
58 #include "sound/zcmusic.h"
59 #include "zc/ffscript.h"
60 #include "dialog/info.h"
61 #include "dialog/alert.h"
62 #include "zc/combos.h"
63 #include "zc/jit.h"
64 #include "zc/zc_subscr.h"
65 #include <fmt/format.h>
66 #include "zconsole/ConsoleLogger.h"
67 #include "zinfo.h"
68 #include "base/misctypes.h"
69 #include "music_playback.h"
70 #include "base/new_menu.h"
71 #include "base/files.h"
72 #include "iter.h"
73
74 #ifdef __EMSCRIPTEN__
75 #include "base/emscripten_utils.h"
76 #endif
77
78 using namespace std::chrono_literals;
79
80 extern bool Playing;
81 int32_t sfx_voice[WAV_COUNT];
82 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
83 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
84
85 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
86 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
87
88 extern byte monochrome_console;
89
90 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
91 extern std::string loadlast;
92 extern char *sfx_string[WAV_COUNT];
93 byte use_dwm_flush;
94 byte use_save_indicator;
95 int32_t paused_midi_pos = 0;
96 byte midi_suspended = 0;
97 byte zc_192b163_warp_compatibility;
98 bool epilepsyFlashReduction;
99 signed char pause_in_background_menu_init = 0;
100 byte pause_in_background = 0;
101 bool is_sys_pal = false;
102 static bool load_control_called_this_frame;
103 extern PALETTE* hw_palette;
104 extern bool update_hw_pal;
105 extern const char* dmaplist(int32_t index, int32_t* list_size);
106 int32_t getnumber(const char *prompt,int32_t initialval);
107
108 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
109 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
110
111 #ifdef ALLEGRO_LINUX
112 static const char *samplepath = "samplesoundset/patches.dat";
113 #endif
114 char qst_files_path[2048];
115
116 extern TopMenu the_player_menu;
117 #ifdef _MSC_VER
118 #define getcwd _getcwd
119 #endif
120
121 bool rF11();
122 bool rI();
123 bool rQ();
124 bool zc_key_pressed();
125
126 #ifdef _WIN32
127
128 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
129 extern "C"
130 {
131 typedef HRESULT(WINAPI *t_DwmFlush)();
132 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
133 }
134
135 void do_DwmFlush()
136 {
137 static HMODULE shell = LoadLibrary("dwmapi.dll");
138
139 if(!shell)
140 return;
141
142 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
143 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
144
145 BOOL enabled;
146 isEnabled(&enabled);
147
148 if(isEnabled)
149 flush();
150 }
151
152 #endif // _WIN32
153
154 323 void zc_exit(int code)
155 {
156 extern CConsoleLoggerEx zscript_coloured_console;
157
158 323 set_is_exiting();
159
160
1/2
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
323 if (replay_get_mode() == ReplayMode::Record) replay_save();
161 323 replay_stop();
162 323 music_stop();
163 323 kill_sfx();
164
165
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 308 times.
323 if (get_qr(qr_OLD_SCRIPT_VOLUME))
166 {
167 //restore user volume settings
168
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1 times.
308 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
169 {
170 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
171 1 }
172
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1 times.
308 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
173 {
174 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
175 1 }
176
2/2
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 1 times.
308 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
177 {
178 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
179 1 }
180
1/2
✓ Branch 0 taken 308 times.
✗ Branch 1 not taken.
308 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
181 {
182 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
183 }
184 308 }
185
1/2
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
323 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
186 {
187 pan_style = (int32_t)FFCore.usr_panstyle;
188 }
189 323 save_game_configs();
190
191 323 zscript_coloured_console.kill();
192 323 zasm_pipeline_shutdown();
193 323 frame_timings_end();
194 323 quit_game();
195
196 323 Z_message("ZQuest Classic website: https://zquestclassic.com\n");
197 323 Z_message("ZQuest Classic docs: https://docs.zquestclassic.com\n");
198
199 323 allegro_exit();
200 323 exit(code);
201 }
202
203 93594 bool flash_reduction_enabled(bool check_qr)
204 {
205
4/4
✓ Branch 0 taken 88914 times.
✓ Branch 1 taken 4680 times.
✓ Branch 2 taken 87624 times.
✓ Branch 3 taken 92304 times.
93594 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
206 }
207
208 // Dialogue largening
209 void large_dialog(DIALOG *d)
210 {
211 large_dialog(d, 1.5);
212 }
213
214 void large_dialog(DIALOG *d, float RESIZE_AMT)
215 {
216 if(!d[0].d1)
217 {
218 d[0].d1 = 1;
219 int32_t oldwidth = d[0].w;
220 int32_t oldheight = d[0].h;
221 int32_t oldx = d[0].x;
222 int32_t oldy = d[0].y;
223 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
224 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
225 d[0].w = int32_t(d[0].w*RESIZE_AMT);
226 d[0].h = int32_t(d[0].h*RESIZE_AMT);
227
228 for(int32_t i=1; d[i].proc !=NULL; i++)
229 {
230 // Place elements horizontally
231 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
232 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
233
234 if(d[i].proc != d_stringloader)
235 {
236 if(d[i].proc==d_bitmap_proc)
237 {
238 d[i].w *= 2;
239 }
240 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
241 }
242
243 // Place elements vertically
244 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
245 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
246
247 // Vertically resize elements
248 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
249 {
250 d[i].h = int32_t((double)d[i].h*1.5);
251 }
252 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
253 {
254 d[i].y += int32_t((double)d[i].h*0.25);
255 d[i].h = int32_t((double)d[i].h*1.25);
256 }
257 else if(d[i].proc==d_bitmap_proc)
258 {
259 d[i].h *= 2;
260 }
261 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
262
263 // Fix frames
264 if(d[i].proc == jwin_frame_proc)
265 {
266 d[i].x++;
267 d[i].y++;
268 d[i].w-=4;
269 d[i].h-=4;
270 }
271 }
272 }
273
274 for(int32_t i=1; d[i].proc!=NULL; i++)
275 {
276 if(d[i].proc==jwin_slider_proc)
277 continue;
278
279 // Bigger font
280 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
281
282 if(!d[i].dp2 && bigfontproc)
283 {
284 d[i].dp2 = get_zc_font(font_lfont_l);
285 }
286 else if(!bigfontproc)
287 {
288 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
289 }
290
291 // Make checkboxes work
292 if(d[i].proc == jwin_check_proc)
293 d[i].proc = jwin_checkfont_proc;
294 else if(d[i].proc == jwin_radio_proc)
295 d[i].proc = jwin_radiofont_proc;
296 }
297
298 jwin_center_dialog(d);
299 }
300
301 static char cfg_sect[] = "zeldadx"; //We need to rename this.
302 static char ctrl_sect[] = "Controls";
303 static char sfx_sect[] = "Volume";
304
305 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
306 {
307 return D_O_K;
308 }
309
310 bool is_reserved_key(int c)
311 {
312 switch(c)
313 {
314 case KEY_ESC:
315 return true;
316 }
317 return false;
318 }
319 bool is_reserved_keycombo(int c, int modflag)
320 {
321 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
322 return true;
323 return false;
324 }
325 bool checkcheat(Cheat cheat)
326 {
327 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
328 return true; //Main key pressed
329 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
330 return true; //Alt key pressed
331 return false;
332 }
333 323 void load_default_cheatkeys()
334 {
335 323 memset(cheatkeys, 0, sizeof(cheatkeys));
336 323 cheatkeys[Cheat::Life][0] = KEY_H;
337 323 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
338 323 cheatkeys[Cheat::Magic][0] = KEY_M;
339 323 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
340 323 cheatkeys[Cheat::Rupies][0] = KEY_R;
341 323 cheatkeys[Cheat::Bombs][0] = KEY_B;
342 323 cheatkeys[Cheat::Arrows][0] = KEY_A;
343 323 cheatkeys[Cheat::Clock][0] = KEY_I;
344 323 cheatkeys[Cheat::Walls][0] = KEY_F11;
345 323 cheatkeys[Cheat::Fast][0] = KEY_Q;
346 323 cheatkeys[Cheat::Light][0] = KEY_L;
347 323 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
348 323 cheatkeys[Cheat::Kill][0] = KEY_K;
349 323 cheatkeys[Cheat::GoTo][0] = KEY_G;
350 323 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
351 323 cheatkeys[Cheat::ShowL0][0] = KEY_0;
352 323 cheatkeys[Cheat::ShowL1][0] = KEY_1;
353 323 cheatkeys[Cheat::ShowL2][0] = KEY_2;
354 323 cheatkeys[Cheat::ShowL3][0] = KEY_3;
355 323 cheatkeys[Cheat::ShowL4][0] = KEY_4;
356 323 cheatkeys[Cheat::ShowL5][0] = KEY_5;
357 323 cheatkeys[Cheat::ShowL6][0] = KEY_6;
358 323 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
359 323 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
360 323 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
361 323 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
362 323 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
363 323 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
364 323 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
365 323 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
366 323 }
367
368 static bool loaded_game_configs;
369
370 323 void load_game_configs()
371 {
372 323 loaded_game_configs = true;
373 323 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
374 323 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
375 323 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
376 323 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
377 323 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
378 323 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
379 323 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
380 323 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
381 323 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
382 323 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
383 323 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
384 323 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
385 323 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
386 323 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
387
388 //cheat modifier keya
389 323 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
390 323 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
391 323 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
392 323 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
393
394 //cheat keys
395 323 load_default_cheatkeys();
396 char buf[256];
397
2/2
✓ Branch 0 taken 323 times.
✓ Branch 1 taken 11628 times.
11951 for(size_t q = 1; q < Cheat::Last; ++q)
398 {
399
1/2
✓ Branch 0 taken 11628 times.
✗ Branch 1 not taken.
11628 if(!bindable_cheat((Cheat)q)) continue;
400 11628 std::string cheatname = cheat_to_string((Cheat)q);
401
1/2
✓ Branch 0 taken 11628 times.
✗ Branch 1 not taken.
11628 util::lowerstr(cheatname);
402 11628 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
403
1/2
✓ Branch 0 taken 11628 times.
✗ Branch 1 not taken.
11628 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
404 11628 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
405
1/2
✓ Branch 0 taken 11628 times.
✗ Branch 1 not taken.
11628 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
406 11628 }
407
408
1/2
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
323 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
409 joystick_index = 0;
410
411 323 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
412 323 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
413 323 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
414 323 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
415 323 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
416 323 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
417 323 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
418 323 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
419 323 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
420 323 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
421
422 323 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
423 323 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
424 323 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
425 323 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
426
427 323 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
428 323 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
429 323 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
430 323 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
431 323 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
432 323 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
433 323 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
434 323 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
435 323 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
436 323 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
437 323 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
438
439 323 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
440 323 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
441 323 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
442 323 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
443
444 323 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
445
446 323 midi_volume = zc_get_config(sfx_sect,"midi",255);
447 323 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
448 323 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
449 323 pan_style = zc_get_config(sfx_sect,"pan",1);
450 323 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
451 323 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
452 323 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
453 323 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
454 323 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
455 323 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
456 323 ShowBottomPixels = zc_get_config(cfg_sect,"bottom_8_px",0);
457 323 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
458 323 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
459 #ifdef __EMSCRIPTEN__
460 if (em_is_mobile()) NameEntryMode = 2;
461 #endif
462 323 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
463 323 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
464 323 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
465 323 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
466 323 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
467 323 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
468
469 323 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
470 323 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
471 323 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
472 323 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
473 323 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
474 323 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
475 323 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
476
477 323 loadlast = zc_get_config(cfg_sect,"load_last_path","");
478
479 323 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
480
481 323 info_opacity = zc_get_config("zc","debug_info_opacity",255);
482 #ifdef _WIN32
483 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
484 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
485 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
486
487 // This one's for Aero
488 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
489
490 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
491 #else //UNIX
492 323 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
493 323 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
494 #endif
495 323 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
496 323 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
497
498 323 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
499 323 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
500 323 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
501 323 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
502 323 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
503 323 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
504 323 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
505 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
506 323 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1); // TODO: sfxdat is always set to 1 for titlescreen... and 0 in readsfx... so this cfg is pointless, remove?
507 323 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
508 323 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
509 323 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
510 323 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
511 323 }
512
513 void save_control_configs(bool kb)
514 {
515 if(kb)
516 {
517 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
518 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
519 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
520 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
521
522 if (!replay_is_replaying())
523 {
524 zc_set_config(ctrl_sect,"key_a",Akey);
525 zc_set_config(ctrl_sect,"key_b",Bkey);
526 zc_set_config(ctrl_sect,"key_s",Skey);
527 zc_set_config(ctrl_sect,"key_l",Lkey);
528 zc_set_config(ctrl_sect,"key_r",Rkey);
529 zc_set_config(ctrl_sect,"key_p",Pkey);
530 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
531 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
532 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
533 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
534 zc_set_config(ctrl_sect,"key_up", DUkey);
535 zc_set_config(ctrl_sect,"key_down", DDkey);
536 zc_set_config(ctrl_sect,"key_left", DLkey);
537 zc_set_config(ctrl_sect,"key_right",DRkey);
538 }
539 }
540 else
541 {
542 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
543 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
544 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
545 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
546 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
547 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
548 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
549 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
550 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
551 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
552 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
553 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
554 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
555 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
556
557 zc_set_config(ctrl_sect,"btn_a",Abtn);
558 zc_set_config(ctrl_sect,"btn_b",Bbtn);
559 zc_set_config(ctrl_sect,"btn_s",Sbtn);
560 zc_set_config(ctrl_sect,"btn_m",Mbtn);
561 zc_set_config(ctrl_sect,"btn_l",Lbtn);
562 zc_set_config(ctrl_sect,"btn_r",Rbtn);
563 zc_set_config(ctrl_sect,"btn_p",Pbtn);
564 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
565 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
566 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
567 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
568
569 zc_set_config(ctrl_sect,"btn_up",DUbtn);
570 zc_set_config(ctrl_sect,"btn_down",DDbtn);
571 zc_set_config(ctrl_sect,"btn_left",DLbtn);
572 zc_set_config(ctrl_sect,"btn_right",DRbtn);
573 }
574 }
575
576 void save_cheatkeys()
577 {
578 char buf[256];
579 for(size_t q = 1; q < Cheat::Last; ++q)
580 {
581 if(!bindable_cheat((Cheat)q)) continue;
582 std::string cheatname = cheat_to_string((Cheat)q);
583 util::lowerstr(cheatname);
584 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
585 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
586 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
587 if(cheatkeys[q][1])
588 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
589 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
590 }
591 }
592
593 323 void save_game_configs()
594 {
595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 323 times.
323 if (!loaded_game_configs) return;
596
597 323 packfile_password("");
598
599
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 323 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
323 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
600 {
601 int o_window_x, o_window_y;
602 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
603 zc_set_config(cfg_sect,"window_x",o_window_x);
604 zc_set_config(cfg_sect,"window_y",o_window_y);
605 }
606
607
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 323 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
323 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
608 {
609 window_width = al_get_display_width(all_get_display());
610 window_height = al_get_display_height(all_get_display());
611 zc_set_config(cfg_sect,"window_width",window_width);
612 zc_set_config(cfg_sect,"window_height",window_height);
613 }
614
615 323 zc_set_config(cfg_sect,"load_last_path",loadlast.c_str());
616 323 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
617
618 323 flush_config_file();
619 #ifdef __EMSCRIPTEN__
620 em_sync_fs();
621 #endif
622 323 }
623
624 //----------------------------------------------------------------
625
626 // Timers
627
628 41855 void fps_callback()
629 {
630 41855 lastfps=framecnt;
631 41855 framecnt=0;
632 41855 }
633
634 END_OF_FUNCTION(fps_callback)
635
636 323 int32_t Z_init_timers()
637 {
638 static bool didit = false;
639 const static char *err_str = "Couldn't allocate timer";
640 323 err_str = err_str; //Unused variable warning
641
642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 323 times.
323 if(didit)
643 return 1;
644
645 323 didit = true;
646
647 LOCK_VARIABLE(lastfps);
648 LOCK_VARIABLE(framecnt);
649 LOCK_FUNCTION(fps_callback);
650
651
1/2
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
323 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
652 return 0;
653
654 323 return 1;
655 323 }
656
657 323 void Z_remove_timers()
658 {
659 323 remove_int(fps_callback);
660 323 }
661
662 //----------------------------------------------------------------
663
664 void dump_pal(BITMAP *dest)
665 {
666 for(int32_t i=0; i<256; i++)
667 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
668 }
669
670 //----------------------------------------------------------------
671
672 int game_mouse_index = ZCM_BLANK;
673 static bool system_mouse = false;
674 118 bool sys_mouse()
675 {
676 118 system_mouse = true;
677 118 return MouseSprite::set(ZCM_NORMAL);
678 }
679 1698 bool game_mouse()
680 {
681 1698 system_mouse = false;
682 1698 return MouseSprite::set(game_mouse_index);
683 }
684 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
685 {
686 if(!bmp)
687 return;
688 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
689 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
690 if(bmp->w == scaledw && bmp->h == scaledh)
691 user_scale = false;
692 if(user_scale || sys_recolor)
693 {
694 if(!user_scale) scale = 1;
695 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
696 if(user_scale)
697 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
698 else
699 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
700 if(sys_recolor)
701 recolor_mouse(tmpbmp);
702 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
703 destroy_bitmap(tmpbmp);
704 }
705 else
706 {
707 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
708 }
709 }
710
711 //Handles converting the mouse sprite from the .dat file
712 void recolor_mouse(BITMAP* bmp)
713 {
714 for(int32_t x = 0; x < bmp->w; ++x)
715 {
716 for(int32_t y = 0; y < bmp->h; ++y)
717 {
718 int32_t color = getpixel(bmp, x, y);
719 switch(color)
720 {
721 case dvc(1):
722 color = jwin_pal[jcCURSORMISC];
723 break;
724 case dvc(2):
725 color = jwin_pal[jcCURSOROUTLINE];
726 break;
727 case dvc(3):
728 color = jwin_pal[jcCURSORLIGHT];
729 break;
730 case dvc(5):
731 color = jwin_pal[jcCURSORDARK];
732 break;
733 default:
734 continue;
735 }
736 putpixel(bmp, x, y, color);
737 }
738 }
739 }
740 void load_mouse()
741 {
742 PALETTE pal;
743 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
744 if (!cursor_bitmap)
745 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
746
747 enter_sys_pal();
748 MouseSprite::set(-1);
749 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
750 int32_t sz = 16*scale;
751 for(int32_t j = 0; j < 1; ++j)
752 {
753 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
754 if(zcmouse[j])
755 destroy_bitmap(zcmouse[j]);
756 zcmouse[j] = create_bitmap_ex(8,sz,sz);
757 clear_bitmap(zcmouse[j]);
758 clear_bitmap(tmpbmp);
759 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
760 recolor_mouse(tmpbmp);
761 if(sz!=16)
762 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
763 else
764 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
765 destroy_bitmap(tmpbmp);
766 }
767 if(!hw_palette) hw_palette = &RAMpal;
768 zc_set_palette(*hw_palette);
769
770 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
771 clear_bitmap(blankmouse);
772
773 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
774 MouseSprite::assign(ZCM_BLANK, blankmouse);
775 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
776
777 //Reload the mouse
778 if(system_mouse)
779 sys_mouse();
780 else game_mouse();
781
782 destroy_bitmap(blankmouse);
783 destroy_bitmap(cursor_bitmap);
784 exit_sys_pal();
785 }
786
787 // sets the video mode and initializes the palette and mouse sprite
788 323 bool game_vid_mode(int32_t mode,int32_t wait)
789 {
790
1/2
✓ Branch 0 taken 323 times.
✗ Branch 1 not taken.
323 if (is_headless())
791 323 return true;
792
793 extern int zq_screen_w, zq_screen_h;
794 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
795 {
796 return false;
797 }
798
799 scrx = (resx-320)>>1;
800 scry = (resy-240)>>1;
801 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
802 zcmouse[q] = NULL;
803 load_mouse();
804
805 for(int32_t i=240; i<256; i++)
806 RAMpal[i]=pal_gui[i];
807
808 zc_set_palette(RAMpal);
809 clear_to_color(screen,BLACK);
810
811 rest(wait);
812 return true;
813 323 }
814
815 331 void null_quest()
816 {
817
1/2
✓ Branch 0 taken 331 times.
✗ Branch 1 not taken.
331 std::string title_assets_path = "modules/classic/title_gfx.dat";
818
2/4
✓ Branch 0 taken 331 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 331 times.
331 if (get_last_loaded_qstpath() == title_assets_path)
819 return;
820
821 byte skip_flags[4];
822
2/2
✓ Branch 0 taken 331 times.
✓ Branch 1 taken 8606 times.
8937 for (int i = 0; i < skip_max; i++)
823
1/2
✓ Branch 0 taken 8606 times.
✗ Branch 1 not taken.
8606 set_bit(skip_flags, i, 1);
824
1/2
✓ Branch 0 taken 331 times.
✗ Branch 1 not taken.
331 set_bit(skip_flags, skip_tiles, 0);
825
1/2
✓ Branch 0 taken 331 times.
✗ Branch 1 not taken.
331 set_bit(skip_flags, skip_csets, 0);
826
1/2
✓ Branch 0 taken 331 times.
✗ Branch 1 not taken.
331 set_bit(skip_flags, skip_misc, 0); // needed for miscsfx (skip this and `tests/replays/demons_inferno/demons_inferno_1_of_2.zplay` fails).
827
1/2
✓ Branch 0 taken 331 times.
✗ Branch 1 not taken.
331 loadquest(title_assets_path.c_str(), &QHeader, &QMisc, tunes+ZC_MIDI_COUNT, false, skip_flags, 0, false);
828 331 sfxdat = 1;
829 // TODO: sfx.dat is ~1.2 MB. Could be better to break that up into individual files and load on demand / not at startup.
830 // TODO: can we cache the tiles/colordata so we don't have to read title_gfx.dat more than once?
831 // colordata is tiny, but tilebuf is huge, so limit that to just what the title screen needs.
832 // Another option: embed this data into the binary (`xxd -i resources/modules/classic/title_gfx.dat > title_gfx.h`)
833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 331 times.
331 }
834
835 331 void init_NES_mode()
836 {
837 331 null_quest();
838 331 }
839
840 //----------------------------------------------------------------
841
842 qword trianglelines[16]=
843 {
844 0x0000000000000000ULL,
845 0xFD00000000000000ULL,
846 0xFDFD000000000000ULL,
847 0xFDFDFD0000000000ULL,
848 0xFDFDFDFD00000000ULL,
849 0xFDFDFDFDFD000000ULL,
850 0xFDFDFDFDFDFD0000ULL,
851 0xFDFDFDFDFDFDFD00ULL,
852 0xFDFDFDFDFDFDFDFDULL,
853 0x00FDFDFDFDFDFDFDULL,
854 0x0000FDFDFDFDFDFDULL,
855 0x000000FDFDFDFDFDULL,
856 0x00000000FDFDFDFDULL,
857 0x0000000000FDFDFDULL,
858 0x000000000000FDFDULL,
859 0x00000000000000FDULL,
860 };
861
862 word screen_triangles[29][32];
863
864 // the ULL suffixes are to prevent this warning:
865 // warning: integer constant is too large for "int32_t" type
866
867 qword triangles[4][16][8]= //[direction][value][line]
868 {
869 {
870 {
871 0x0000000000000000ULL,
872 0x0000000000000000ULL,
873 0x0000000000000000ULL,
874 0x0000000000000000ULL,
875 0x0000000000000000ULL,
876 0x0000000000000000ULL,
877 0x0000000000000000ULL,
878 0x0000000000000000ULL
879 },
880 {
881 0xFD00000000000000ULL,
882 0x0000000000000000ULL,
883 0x0000000000000000ULL,
884 0x0000000000000000ULL,
885 0x0000000000000000ULL,
886 0x0000000000000000ULL,
887 0x0000000000000000ULL,
888 0x0000000000000000ULL
889 },
890 {
891 0xFDFD000000000000ULL,
892 0xFD00000000000000ULL,
893 0x0000000000000000ULL,
894 0x0000000000000000ULL,
895 0x0000000000000000ULL,
896 0x0000000000000000ULL,
897 0x0000000000000000ULL,
898 0x0000000000000000ULL
899 },
900 {
901 0xFDFDFD0000000000ULL,
902 0xFDFD000000000000ULL,
903 0xFD00000000000000ULL,
904 0x0000000000000000ULL,
905 0x0000000000000000ULL,
906 0x0000000000000000ULL,
907 0x0000000000000000ULL,
908 0x0000000000000000ULL
909 },
910 {
911 0xFDFDFDFD00000000ULL,
912 0xFDFDFD0000000000ULL,
913 0xFDFD000000000000ULL,
914 0xFD00000000000000ULL,
915 0x0000000000000000ULL,
916 0x0000000000000000ULL,
917 0x0000000000000000ULL,
918 0x0000000000000000ULL
919 },
920 {
921 0xFDFDFDFDFD000000ULL,
922 0xFDFDFDFD00000000ULL,
923 0xFDFDFD0000000000ULL,
924 0xFDFD000000000000ULL,
925 0xFD00000000000000ULL,
926 0x0000000000000000ULL,
927 0x0000000000000000ULL,
928 0x0000000000000000ULL
929 },
930 {
931 0xFDFDFDFDFDFD0000ULL,
932 0xFDFDFDFDFD000000ULL,
933 0xFDFDFDFD00000000ULL,
934 0xFDFDFD0000000000ULL,
935 0xFDFD000000000000ULL,
936 0xFD00000000000000ULL,
937 0x0000000000000000ULL,
938 0x0000000000000000ULL
939 },
940 {
941 0xFDFDFDFDFDFDFD00ULL,
942 0xFDFDFDFDFDFD0000ULL,
943 0xFDFDFDFDFD000000ULL,
944 0xFDFDFDFD00000000ULL,
945 0xFDFDFD0000000000ULL,
946 0xFDFD000000000000ULL,
947 0xFD00000000000000ULL,
948 0x0000000000000000ULL
949 },
950 {
951 0xFDFDFDFDFDFDFDFDULL,
952 0xFDFDFDFDFDFDFD00ULL,
953 0xFDFDFDFDFDFD0000ULL,
954 0xFDFDFDFDFD000000ULL,
955 0xFDFDFDFD00000000ULL,
956 0xFDFDFD0000000000ULL,
957 0xFDFD000000000000ULL,
958 0xFD00000000000000ULL
959 },
960 {
961 0xFDFDFDFDFDFDFDFDULL,
962 0xFDFDFDFDFDFDFDFDULL,
963 0xFDFDFDFDFDFDFD00ULL,
964 0xFDFDFDFDFDFD0000ULL,
965 0xFDFDFDFDFD000000ULL,
966 0xFDFDFDFD00000000ULL,
967 0xFDFDFD0000000000ULL,
968 0xFDFD000000000000ULL
969 },
970 {
971 0xFDFDFDFDFDFDFDFDULL,
972 0xFDFDFDFDFDFDFDFDULL,
973 0xFDFDFDFDFDFDFDFDULL,
974 0xFDFDFDFDFDFDFD00ULL,
975 0xFDFDFDFDFDFD0000ULL,
976 0xFDFDFDFDFD000000ULL,
977 0xFDFDFDFD00000000ULL,
978 0xFDFDFD0000000000ULL
979 },
980 {
981 0xFDFDFDFDFDFDFDFDULL,
982 0xFDFDFDFDFDFDFDFDULL,
983 0xFDFDFDFDFDFDFDFDULL,
984 0xFDFDFDFDFDFDFDFDULL,
985 0xFDFDFDFDFDFDFD00ULL,
986 0xFDFDFDFDFDFD0000ULL,
987 0xFDFDFDFDFD000000ULL,
988 0xFDFDFDFD00000000ULL
989 },
990 {
991 0xFDFDFDFDFDFDFDFDULL,
992 0xFDFDFDFDFDFDFDFDULL,
993 0xFDFDFDFDFDFDFDFDULL,
994 0xFDFDFDFDFDFDFDFDULL,
995 0xFDFDFDFDFDFDFDFDULL,
996 0xFDFDFDFDFDFDFD00ULL,
997 0xFDFDFDFDFDFD0000ULL,
998 0xFDFDFDFDFD000000ULL
999 },
1000 {
1001 0xFDFDFDFDFDFDFDFDULL,
1002 0xFDFDFDFDFDFDFDFDULL,
1003 0xFDFDFDFDFDFDFDFDULL,
1004 0xFDFDFDFDFDFDFDFDULL,
1005 0xFDFDFDFDFDFDFDFDULL,
1006 0xFDFDFDFDFDFDFDFDULL,
1007 0xFDFDFDFDFDFDFD00ULL,
1008 0xFDFDFDFDFDFD0000ULL
1009 },
1010 {
1011 0xFDFDFDFDFDFDFDFDULL,
1012 0xFDFDFDFDFDFDFDFDULL,
1013 0xFDFDFDFDFDFDFDFDULL,
1014 0xFDFDFDFDFDFDFDFDULL,
1015 0xFDFDFDFDFDFDFDFDULL,
1016 0xFDFDFDFDFDFDFDFDULL,
1017 0xFDFDFDFDFDFDFDFDULL,
1018 0xFDFDFDFDFDFDFD00ULL
1019 },
1020 {
1021 0xFDFDFDFDFDFDFDFDULL,
1022 0xFDFDFDFDFDFDFDFDULL,
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFDFDULL,
1025 0xFDFDFDFDFDFDFDFDULL,
1026 0xFDFDFDFDFDFDFDFDULL,
1027 0xFDFDFDFDFDFDFDFDULL,
1028 0xFDFDFDFDFDFDFDFDULL
1029 }
1030 },
1031 {
1032 {
1033 0x0000000000000000ULL,
1034 0x0000000000000000ULL,
1035 0x0000000000000000ULL,
1036 0x0000000000000000ULL,
1037 0x0000000000000000ULL,
1038 0x0000000000000000ULL,
1039 0x0000000000000000ULL,
1040 0x0000000000000000ULL
1041 },
1042 {
1043 0x00000000000000FDULL,
1044 0x0000000000000000ULL,
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL,
1047 0x0000000000000000ULL,
1048 0x0000000000000000ULL,
1049 0x0000000000000000ULL,
1050 0x0000000000000000ULL
1051 },
1052 {
1053 0x000000000000FDFDULL,
1054 0x00000000000000FDULL,
1055 0x0000000000000000ULL,
1056 0x0000000000000000ULL,
1057 0x0000000000000000ULL,
1058 0x0000000000000000ULL,
1059 0x0000000000000000ULL,
1060 0x0000000000000000ULL
1061 },
1062 {
1063 0x0000000000FDFDFDULL,
1064 0x000000000000FDFDULL,
1065 0x00000000000000FDULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL,
1068 0x0000000000000000ULL,
1069 0x0000000000000000ULL,
1070 0x0000000000000000ULL
1071 },
1072 {
1073 0x00000000FDFDFDFDULL,
1074 0x0000000000FDFDFDULL,
1075 0x000000000000FDFDULL,
1076 0x00000000000000FDULL,
1077 0x0000000000000000ULL,
1078 0x0000000000000000ULL,
1079 0x0000000000000000ULL,
1080 0x0000000000000000ULL
1081 },
1082 {
1083 0x000000FDFDFDFDFDULL,
1084 0x00000000FDFDFDFDULL,
1085 0x0000000000FDFDFDULL,
1086 0x000000000000FDFDULL,
1087 0x00000000000000FDULL,
1088 0x0000000000000000ULL,
1089 0x0000000000000000ULL,
1090 0x0000000000000000ULL
1091 },
1092 {
1093 0x0000FDFDFDFDFDFDULL,
1094 0x000000FDFDFDFDFDULL,
1095 0x00000000FDFDFDFDULL,
1096 0x0000000000FDFDFDULL,
1097 0x000000000000FDFDULL,
1098 0x00000000000000FDULL,
1099 0x0000000000000000ULL,
1100 0x0000000000000000ULL
1101 },
1102 {
1103 0x00FDFDFDFDFDFDFDULL,
1104 0x0000FDFDFDFDFDFDULL,
1105 0x000000FDFDFDFDFDULL,
1106 0x00000000FDFDFDFDULL,
1107 0x0000000000FDFDFDULL,
1108 0x000000000000FDFDULL,
1109 0x00000000000000FDULL,
1110 0x0000000000000000ULL
1111 },
1112 {
1113 0xFDFDFDFDFDFDFDFDULL,
1114 0x00FDFDFDFDFDFDFDULL,
1115 0x0000FDFDFDFDFDFDULL,
1116 0x000000FDFDFDFDFDULL,
1117 0x00000000FDFDFDFDULL,
1118 0x0000000000FDFDFDULL,
1119 0x000000000000FDFDULL,
1120 0x00000000000000FDULL
1121 },
1122 {
1123 0xFDFDFDFDFDFDFDFDULL,
1124 0xFDFDFDFDFDFDFDFDULL,
1125 0x00FDFDFDFDFDFDFDULL,
1126 0x0000FDFDFDFDFDFDULL,
1127 0x000000FDFDFDFDFDULL,
1128 0x00000000FDFDFDFDULL,
1129 0x0000000000FDFDFDULL,
1130 0x000000000000FDFDULL
1131 },
1132 {
1133 0xFDFDFDFDFDFDFDFDULL,
1134 0xFDFDFDFDFDFDFDFDULL,
1135 0xFDFDFDFDFDFDFDFDULL,
1136 0x00FDFDFDFDFDFDFDULL,
1137 0x0000FDFDFDFDFDFDULL,
1138 0x000000FDFDFDFDFDULL,
1139 0x00000000FDFDFDFDULL,
1140 0x0000000000FDFDFDULL
1141 },
1142 {
1143 0xFDFDFDFDFDFDFDFDULL,
1144 0xFDFDFDFDFDFDFDFDULL,
1145 0xFDFDFDFDFDFDFDFDULL,
1146 0xFDFDFDFDFDFDFDFDULL,
1147 0x00FDFDFDFDFDFDFDULL,
1148 0x0000FDFDFDFDFDFDULL,
1149 0x000000FDFDFDFDFDULL,
1150 0x00000000FDFDFDFDULL
1151 },
1152 {
1153 0xFDFDFDFDFDFDFDFDULL,
1154 0xFDFDFDFDFDFDFDFDULL,
1155 0xFDFDFDFDFDFDFDFDULL,
1156 0xFDFDFDFDFDFDFDFDULL,
1157 0xFDFDFDFDFDFDFDFDULL,
1158 0x00FDFDFDFDFDFDFDULL,
1159 0x0000FDFDFDFDFDFDULL,
1160 0x000000FDFDFDFDFDULL
1161 },
1162 {
1163 0xFDFDFDFDFDFDFDFDULL,
1164 0xFDFDFDFDFDFDFDFDULL,
1165 0xFDFDFDFDFDFDFDFDULL,
1166 0xFDFDFDFDFDFDFDFDULL,
1167 0xFDFDFDFDFDFDFDFDULL,
1168 0xFDFDFDFDFDFDFDFDULL,
1169 0x00FDFDFDFDFDFDFDULL,
1170 0x0000FDFDFDFDFDFDULL
1171 },
1172 {
1173 0xFDFDFDFDFDFDFDFDULL,
1174 0xFDFDFDFDFDFDFDFDULL,
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0xFDFDFDFDFDFDFDFDULL,
1177 0xFDFDFDFDFDFDFDFDULL,
1178 0xFDFDFDFDFDFDFDFDULL,
1179 0xFDFDFDFDFDFDFDFDULL,
1180 0x00FDFDFDFDFDFDFDULL
1181 },
1182 {
1183 0xFDFDFDFDFDFDFDFDULL,
1184 0xFDFDFDFDFDFDFDFDULL,
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0xFDFDFDFDFDFDFDFDULL,
1188 0xFDFDFDFDFDFDFDFDULL,
1189 0xFDFDFDFDFDFDFDFDULL,
1190 0xFDFDFDFDFDFDFDFDULL
1191 }
1192 },
1193 {
1194 {
1195 0x0000000000000000ULL,
1196 0x0000000000000000ULL,
1197 0x0000000000000000ULL,
1198 0x0000000000000000ULL,
1199 0x0000000000000000ULL,
1200 0x0000000000000000ULL,
1201 0x0000000000000000ULL,
1202 0x0000000000000000ULL
1203 },
1204 {
1205 0x0000000000000000ULL,
1206 0x0000000000000000ULL,
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL,
1209 0x0000000000000000ULL,
1210 0x0000000000000000ULL,
1211 0x0000000000000000ULL,
1212 0xFD00000000000000ULL
1213 },
1214 {
1215 0x0000000000000000ULL,
1216 0x0000000000000000ULL,
1217 0x0000000000000000ULL,
1218 0x0000000000000000ULL,
1219 0x0000000000000000ULL,
1220 0x0000000000000000ULL,
1221 0xFD00000000000000ULL,
1222 0xFDFD000000000000ULL
1223 },
1224 {
1225 0x0000000000000000ULL,
1226 0x0000000000000000ULL,
1227 0x0000000000000000ULL,
1228 0x0000000000000000ULL,
1229 0x0000000000000000ULL,
1230 0xFD00000000000000ULL,
1231 0xFDFD000000000000ULL,
1232 0xFDFDFD0000000000ULL
1233 },
1234 {
1235 0x0000000000000000ULL,
1236 0x0000000000000000ULL,
1237 0x0000000000000000ULL,
1238 0x0000000000000000ULL,
1239 0xFD00000000000000ULL,
1240 0xFDFD000000000000ULL,
1241 0xFDFDFD0000000000ULL,
1242 0xFDFDFDFD00000000ULL
1243 },
1244 {
1245 0x0000000000000000ULL,
1246 0x0000000000000000ULL,
1247 0x0000000000000000ULL,
1248 0xFD00000000000000ULL,
1249 0xFDFD000000000000ULL,
1250 0xFDFDFD0000000000ULL,
1251 0xFDFDFDFD00000000ULL,
1252 0xFDFDFDFDFD000000ULL
1253 },
1254 {
1255 0x0000000000000000ULL,
1256 0x0000000000000000ULL,
1257 0xFD00000000000000ULL,
1258 0xFDFD000000000000ULL,
1259 0xFDFDFD0000000000ULL,
1260 0xFDFDFDFD00000000ULL,
1261 0xFDFDFDFDFD000000ULL,
1262 0xFDFDFDFDFDFD0000ULL
1263 },
1264 {
1265 0x0000000000000000ULL,
1266 0xFD00000000000000ULL,
1267 0xFDFD000000000000ULL,
1268 0xFDFDFD0000000000ULL,
1269 0xFDFDFDFD00000000ULL,
1270 0xFDFDFDFDFD000000ULL,
1271 0xFDFDFDFDFDFD0000ULL,
1272 0xFDFDFDFDFDFDFD00ULL
1273 },
1274 {
1275 0xFD00000000000000ULL,
1276 0xFDFD000000000000ULL,
1277 0xFDFDFD0000000000ULL,
1278 0xFDFDFDFD00000000ULL,
1279 0xFDFDFDFDFD000000ULL,
1280 0xFDFDFDFDFDFD0000ULL,
1281 0xFDFDFDFDFDFDFD00ULL,
1282 0xFDFDFDFDFDFDFDFDULL
1283 },
1284 {
1285 0xFDFD000000000000ULL,
1286 0xFDFDFD0000000000ULL,
1287 0xFDFDFDFD00000000ULL,
1288 0xFDFDFDFDFD000000ULL,
1289 0xFDFDFDFDFDFD0000ULL,
1290 0xFDFDFDFDFDFDFD00ULL,
1291 0xFDFDFDFDFDFDFDFDULL,
1292 0xFDFDFDFDFDFDFDFDULL
1293 },
1294 {
1295 0xFDFDFD0000000000ULL,
1296 0xFDFDFDFD00000000ULL,
1297 0xFDFDFDFDFD000000ULL,
1298 0xFDFDFDFDFDFD0000ULL,
1299 0xFDFDFDFDFDFDFD00ULL,
1300 0xFDFDFDFDFDFDFDFDULL,
1301 0xFDFDFDFDFDFDFDFDULL,
1302 0xFDFDFDFDFDFDFDFDULL
1303 },
1304 {
1305 0xFDFDFDFD00000000ULL,
1306 0xFDFDFDFDFD000000ULL,
1307 0xFDFDFDFDFDFD0000ULL,
1308 0xFDFDFDFDFDFDFD00ULL,
1309 0xFDFDFDFDFDFDFDFDULL,
1310 0xFDFDFDFDFDFDFDFDULL,
1311 0xFDFDFDFDFDFDFDFDULL,
1312 0xFDFDFDFDFDFDFDFDULL
1313 },
1314 {
1315 0xFDFDFDFDFD000000ULL,
1316 0xFDFDFDFDFDFD0000ULL,
1317 0xFDFDFDFDFDFDFD00ULL,
1318 0xFDFDFDFDFDFDFDFDULL,
1319 0xFDFDFDFDFDFDFDFDULL,
1320 0xFDFDFDFDFDFDFDFDULL,
1321 0xFDFDFDFDFDFDFDFDULL,
1322 0xFDFDFDFDFDFDFDFDULL
1323 },
1324 {
1325 0xFDFDFDFDFDFD0000ULL,
1326 0xFDFDFDFDFDFDFD00ULL,
1327 0xFDFDFDFDFDFDFDFDULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL,
1330 0xFDFDFDFDFDFDFDFDULL,
1331 0xFDFDFDFDFDFDFDFDULL,
1332 0xFDFDFDFDFDFDFDFDULL
1333 },
1334 {
1335 0xFDFDFDFDFDFDFD00ULL,
1336 0xFDFDFDFDFDFDFDFDULL,
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL,
1340 0xFDFDFDFDFDFDFDFDULL,
1341 0xFDFDFDFDFDFDFDFDULL,
1342 0xFDFDFDFDFDFDFDFDULL
1343 },
1344 {
1345 0xFDFDFDFDFDFDFDFDULL,
1346 0xFDFDFDFDFDFDFDFDULL,
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL,
1350 0xFDFDFDFDFDFDFDFDULL,
1351 0xFDFDFDFDFDFDFDFDULL,
1352 0xFDFDFDFDFDFDFDFDULL
1353 }
1354 },
1355 {
1356 {
1357 0x0000000000000000ULL,
1358 0x0000000000000000ULL,
1359 0x0000000000000000ULL,
1360 0x0000000000000000ULL,
1361 0x0000000000000000ULL,
1362 0x0000000000000000ULL,
1363 0x0000000000000000ULL,
1364 0x0000000000000000ULL
1365 },
1366 {
1367 0x0000000000000000ULL,
1368 0x0000000000000000ULL,
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL,
1371 0x0000000000000000ULL,
1372 0x0000000000000000ULL,
1373 0x0000000000000000ULL,
1374 0x00000000000000FDULL
1375 },
1376 {
1377 0x0000000000000000ULL,
1378 0x0000000000000000ULL,
1379 0x0000000000000000ULL,
1380 0x0000000000000000ULL,
1381 0x0000000000000000ULL,
1382 0x0000000000000000ULL,
1383 0x00000000000000FDULL,
1384 0x000000000000FDFDULL
1385 },
1386 {
1387 0x0000000000000000ULL,
1388 0x0000000000000000ULL,
1389 0x0000000000000000ULL,
1390 0x0000000000000000ULL,
1391 0x0000000000000000ULL,
1392 0x00000000000000FDULL,
1393 0x000000000000FDFDULL,
1394 0x0000000000FDFDFDULL
1395 },
1396 {
1397 0x0000000000000000ULL,
1398 0x0000000000000000ULL,
1399 0x0000000000000000ULL,
1400 0x0000000000000000ULL,
1401 0x00000000000000FDULL,
1402 0x000000000000FDFDULL,
1403 0x0000000000FDFDFDULL,
1404 0x00000000FDFDFDFDULL
1405 },
1406 {
1407 0x0000000000000000ULL,
1408 0x0000000000000000ULL,
1409 0x0000000000000000ULL,
1410 0x00000000000000FDULL,
1411 0x000000000000FDFDULL,
1412 0x0000000000FDFDFDULL,
1413 0x00000000FDFDFDFDULL,
1414 0x000000FDFDFDFDFDULL
1415 },
1416 {
1417 0x0000000000000000ULL,
1418 0x0000000000000000ULL,
1419 0x00000000000000FDULL,
1420 0x000000000000FDFDULL,
1421 0x0000000000FDFDFDULL,
1422 0x00000000FDFDFDFDULL,
1423 0x000000FDFDFDFDFDULL,
1424 0x0000FDFDFDFDFDFDULL
1425 },
1426 {
1427 0x0000000000000000ULL,
1428 0x00000000000000FDULL,
1429 0x000000000000FDFDULL,
1430 0x0000000000FDFDFDULL,
1431 0x00000000FDFDFDFDULL,
1432 0x000000FDFDFDFDFDULL,
1433 0x0000FDFDFDFDFDFDULL,
1434 0x00FDFDFDFDFDFDFDULL
1435 },
1436 {
1437 0x00000000000000FDULL,
1438 0x000000000000FDFDULL,
1439 0x0000000000FDFDFDULL,
1440 0x00000000FDFDFDFDULL,
1441 0x000000FDFDFDFDFDULL,
1442 0x0000FDFDFDFDFDFDULL,
1443 0x00FDFDFDFDFDFDFDULL,
1444 0xFDFDFDFDFDFDFDFDULL
1445 },
1446 {
1447 0x000000000000FDFDULL,
1448 0x0000000000FDFDFDULL,
1449 0x00000000FDFDFDFDULL,
1450 0x000000FDFDFDFDFDULL,
1451 0x0000FDFDFDFDFDFDULL,
1452 0x00FDFDFDFDFDFDFDULL,
1453 0xFDFDFDFDFDFDFDFDULL,
1454 0xFDFDFDFDFDFDFDFDULL
1455 },
1456 {
1457 0x0000000000FDFDFDULL,
1458 0x00000000FDFDFDFDULL,
1459 0x000000FDFDFDFDFDULL,
1460 0x0000FDFDFDFDFDFDULL,
1461 0x00FDFDFDFDFDFDFDULL,
1462 0xFDFDFDFDFDFDFDFDULL,
1463 0xFDFDFDFDFDFDFDFDULL,
1464 0xFDFDFDFDFDFDFDFDULL
1465 },
1466 {
1467 0x00000000FDFDFDFDULL,
1468 0x000000FDFDFDFDFDULL,
1469 0x0000FDFDFDFDFDFDULL,
1470 0x00FDFDFDFDFDFDFDULL,
1471 0xFDFDFDFDFDFDFDFDULL,
1472 0xFDFDFDFDFDFDFDFDULL,
1473 0xFDFDFDFDFDFDFDFDULL,
1474 0xFDFDFDFDFDFDFDFDULL
1475 },
1476 {
1477 0x000000FDFDFDFDFDULL,
1478 0x0000FDFDFDFDFDFDULL,
1479 0x00FDFDFDFDFDFDFDULL,
1480 0xFDFDFDFDFDFDFDFDULL,
1481 0xFDFDFDFDFDFDFDFDULL,
1482 0xFDFDFDFDFDFDFDFDULL,
1483 0xFDFDFDFDFDFDFDFDULL,
1484 0xFDFDFDFDFDFDFDFDULL
1485 },
1486 {
1487 0x0000FDFDFDFDFDFDULL,
1488 0x00FDFDFDFDFDFDFDULL,
1489 0xFDFDFDFDFDFDFDFDULL,
1490 0xFDFDFDFDFDFDFDFDULL,
1491 0xFDFDFDFDFDFDFDFDULL,
1492 0xFDFDFDFDFDFDFDFDULL,
1493 0xFDFDFDFDFDFDFDFDULL,
1494 0xFDFDFDFDFDFDFDFDULL
1495 },
1496 {
1497 0x00FDFDFDFDFDFDFDULL,
1498 0xFDFDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL,
1500 0xFDFDFDFDFDFDFDFDULL,
1501 0xFDFDFDFDFDFDFDFDULL,
1502 0xFDFDFDFDFDFDFDFDULL,
1503 0xFDFDFDFDFDFDFDFDULL,
1504 0xFDFDFDFDFDFDFDFDULL
1505 },
1506 {
1507 0xFDFDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL,
1511 0xFDFDFDFDFDFDFDFDULL,
1512 0xFDFDFDFDFDFDFDFDULL,
1513 0xFDFDFDFDFDFDFDFDULL,
1514 0xFDFDFDFDFDFDFDFDULL
1515 }
1516 }
1517 };
1518
1519 static bool is_opening_screen;
1520 int32_t black_opening_count=0;
1521 int32_t black_opening_x,black_opening_y;
1522 int32_t black_opening_shape;
1523
1524 3422 int32_t choose_opening_shape()
1525 {
1526 // First, count how many bits are set
1527 3422 int32_t numBits=0;
1528 int32_t bitCounter;
1529
1530
2/2
✓ Branch 0 taken 17110 times.
✓ Branch 1 taken 3422 times.
20532 for(int32_t i=0; i<bosMAX; i++)
1531 {
1532
2/2
✓ Branch 0 taken 13472 times.
✓ Branch 1 taken 3638 times.
17110 if(COOLSCROLL&(1<<i))
1533 3638 numBits++;
1534 17110 }
1535
1536 // Shouldn't happen...
1537
1/2
✓ Branch 0 taken 3422 times.
✗ Branch 1 not taken.
3422 if(numBits==0)
1538 return bosCIRCLE;
1539
1540 // Pick a bit
1541 3422 bitCounter=zc_rand()%numBits+1;
1542
1543
2/2
✓ Branch 0 taken 4891 times.
✓ Branch 1 taken 26 times.
4917 for(int32_t i=0; i<bosMAX; i++)
1544 {
1545 // If this bit is set, decrement the bit counter
1546
2/2
✓ Branch 0 taken 1339 times.
✓ Branch 1 taken 3552 times.
4891 if(COOLSCROLL&(1<<i))
1547 3552 bitCounter--;
1548
1549 // When the counter hits 0, return a value based on
1550 // which bit it stopped on.
1551 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1552
2/2
✓ Branch 0 taken 3396 times.
✓ Branch 1 taken 1495 times.
4891 if(bitCounter==0)
1553 3396 return i;
1554 1495 }
1555
1556 // Shouldn't be necessary, but the compiler might complain, at least
1557 26 return bosCIRCLE;
1558 3422 }
1559
1560 740 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1561 {
1562 740 x -= viewport.x;
1563 740 y -= viewport.y;
1564
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 730 times.
740 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1565
1566 740 int32_t w=framebuf->w, h=framebuf->h;
1567 740 int32_t blockrows=h/8, blockcolumns=32;
1568 740 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1569
1570
2/2
✓ Branch 0 taken 20721 times.
✓ Branch 1 taken 740 times.
21461 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1571 {
1572
2/2
✓ Branch 0 taken 663072 times.
✓ Branch 1 taken 20721 times.
683793 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1573 {
1574
2/2
✓ Branch 0 taken 274113 times.
✓ Branch 1 taken 388959 times.
663072 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1575 663072 }
1576 20721 }
1577
1578 740 black_opening_count = 66;
1579 740 black_opening_x = x;
1580 740 black_opening_y = y;
1581 740 lensclk = 0;
1582 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1583
1584
1585
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 if(black_opening_shape == bosFADEBLACK)
1586 {
1587 refreshTints();
1588 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1589 }
1590
2/2
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 15 times.
740 if(wait)
1591 {
1592 15 FFCore.warpScriptCheck();
1593
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 990 times.
1005 for(int32_t i=0; i<66; i++)
1594 {
1595 990 draw_screen();
1596 990 advanceframe(true);
1597
1598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 990 times.
990 if(Quit)
1599 {
1600 break;
1601 }
1602 990 }
1603 15 }
1604 740 }
1605
1606 2702 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1607 {
1608 2702 x -= viewport.x;
1609 2702 y -= viewport.y;
1610
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2692 times.
2702 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1611
1612 2702 int32_t w=framebuf->w, h=framebuf->h;
1613 2702 int32_t blockrows=h/8, blockcolumns=32;
1614 2702 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1615
1616
2/2
✓ Branch 0 taken 75906 times.
✓ Branch 1 taken 2702 times.
78608 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1617 {
1618
2/2
✓ Branch 0 taken 2428992 times.
✓ Branch 1 taken 75906 times.
2504898 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1619 {
1620
2/2
✓ Branch 0 taken 1201442 times.
✓ Branch 1 taken 1227550 times.
2428992 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1621 2428992 }
1622 75906 }
1623
1624 2702 black_opening_count = -66;
1625 2702 black_opening_x = x;
1626 2702 black_opening_y = y;
1627 2702 lensclk = 0;
1628
1/2
✓ Branch 0 taken 2702 times.
✗ Branch 1 not taken.
2702 if(black_opening_shape == bosFADEBLACK)
1629 {
1630 refreshTints();
1631 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1632 }
1633
2/2
✓ Branch 0 taken 361 times.
✓ Branch 1 taken 2341 times.
2702 if(wait)
1634 {
1635 2341 FFCore.warpScriptCheck();
1636
2/2
✓ Branch 0 taken 2337 times.
✓ Branch 1 taken 154426 times.
156763 for(int32_t i=0; i<66; i++)
1637 {
1638 154426 draw_screen();
1639 154426 advanceframe(true);
1640
1641
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 154422 times.
154426 if(Quit)
1642 {
1643 4 break;
1644 }
1645 154422 }
1646 2341 }
1647 2702 }
1648
1649 226770 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1650 {
1651 226770 clear_to_color(tmp_scr,BLACK);
1652 226770 int32_t w=dest->w, h=dest->h;
1653
1654
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 10867 times.
✓ Branch 3 taken 20394 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 185873 times.
226770 switch(black_opening_shape)
1655 {
1656 case bosOVAL:
1657 {
1658 9636 double new_w=(w/2)+abs(w/2-x);
1659 9636 double new_h=(h/2)+abs(h/2-y);
1660 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1661 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1662 9636 break;
1663 }
1664
1665 case bosTRIANGLE:
1666 {
1667 10867 double new_w=(w/2)+abs(w/2-x);
1668 10867 double new_h=(h/2)+abs(h/2-y);
1669 10867 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1670 10867 double P2= (PI/2);
1671 10867 double P23=(2*PI/3);
1672 10867 double P43=(4*PI/3);
1673 10867 double Pa= (-4*PI*a/(3*max_a));
1674 10867 double angle=P2+Pa;
1675 10867 double a0=angle;
1676 10867 double a2=angle+P23;
1677 10867 double a4=angle+P43;
1678 21734 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1679 10867 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1680 10867 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1681 0);
1682 10867 break;
1683 }
1684
1685 case bosSMAS:
1686 {
1687
2/2
✓ Branch 0 taken 7260 times.
✓ Branch 1 taken 13134 times.
20394 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1688
1689
2/2
✓ Branch 0 taken 571032 times.
✓ Branch 1 taken 20394 times.
591426 for(int32_t blockrow=0; blockrow<h/8; ++blockrow) //30
1690 {
1691
2/2
✓ Branch 0 taken 4568256 times.
✓ Branch 1 taken 571032 times.
5139288 for(int32_t linerow=0; linerow<8; ++linerow)
1692 {
1693 4568256 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1694
1695
2/2
✓ Branch 0 taken 146184192 times.
✓ Branch 1 taken 4568256 times.
150752448 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1696 {
1697 438552576 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1698
6/6
✓ Branch 0 taken 105613064 times.
✓ Branch 1 taken 40571128 times.
✓ Branch 2 taken 96455664 times.
✓ Branch 3 taken 49728528 times.
✓ Branch 4 taken 55884536 times.
✓ Branch 5 taken 40571128 times.
146184192 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1699 146184192 [linerow];
1700 146184192 ++triangleline;
1701 146184192 }
1702 4568256 }
1703 571032 }
1704
1705 20394 break;
1706 }
1707
1708 case bosFADEBLACK:
1709 {
1710 if(black_opening_count<0)
1711 {
1712 black_fade(zc_min(-black_opening_count,63));
1713 }
1714 else if(black_opening_count>0)
1715 {
1716 black_fade(63-zc_max(black_opening_count-3,0));
1717 }
1718 else black_fade(0);
1719 return; //no blitting from tmp_scr!
1720 }
1721
1722 185873 case bosCIRCLE:
1723 default:
1724 {
1725 185873 double new_w=(w/2)+abs(w/2-x);
1726 185873 double new_h=(h/2)+abs(h/2-y);
1727 185873 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1728 //circlefill(tmp_scr,x,y,a<<3,0);
1729 185873 circlefill(tmp_scr,x,y,r,0);
1730 185873 break;
1731 }
1732 }
1733
1734 226770 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1735 226770 }
1736
1737 // fadeamnt is 0-63
1738 void black_fade(int32_t fadeamnt)
1739 {
1740 fadeamnt = _rgb_scale_6[fadeamnt];
1741 for(int32_t i=0; i < 0xEF; i++)
1742 {
1743 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1744 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1745 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1746 }
1747
1748 refreshpal = true;
1749 }
1750
1751 //----------------------------------------------------------------
1752
1753 208658999 bool item_disabled(int32_t item) //is this item disabled?
1754 {
1755
2/2
✓ Branch 0 taken 15091102 times.
✓ Branch 1 taken 193567897 times.
208658999 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1756 }
1757
1758 16267224 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1759 {
1760
2/2
✓ Branch 0 taken 261172 times.
✓ Branch 1 taken 16006052 times.
16267224 if(current_item(item_type, true) >=item)
1761 {
1762 261172 return true;
1763 }
1764
1765 16006052 return false;
1766 16267224 }
1767
1768 45770965 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1769 {
1770
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4628167 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 337472 times.
✓ Branch 6 taken 30509045 times.
✓ Branch 7 taken 10090004 times.
✓ Branch 8 taken 206277 times.
45770965 switch(item_type)
1771 {
1772 case itype_bomb:
1773 case itype_sbomb:
1774 {
1775 int32_t itemid = getItemID(itemsbuf, item_type, it);
1776
1777 if(itemid == -1)
1778 return false;
1779
1780 return (game->get_item(itemid));
1781 }
1782
1783 case itype_clock:
1784 {
1785 4628167 int32_t itemid = getItemID(itemsbuf, item_type, it);
1786
1787
2/4
✓ Branch 0 taken 4628167 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4628167 times.
✗ Branch 3 not taken.
4628167 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1788 return (game->get_item(itemid));
1789 4628167 return Hero.getClock()?1:0;
1790 }
1791
1792 case itype_key:
1793 return (game->get_keys()>0);
1794
1795 case itype_magiccontainer:
1796 return (game->get_maxmagic()>=game->get_mp_per_block());
1797
1798 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1799 {
1800
1/3
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
337472 switch(it)
1801 {
1802 case -2:
1803 {
1804 for(int32_t i=0; i<MAXLEVELS; i++)
1805 {
1806 if(game->lvlitems[i]&(1 << li_mcguffin))
1807 {
1808 return true;
1809 }
1810 }
1811
1812 return false;
1813 }
1814
1815 case -1:
1816 return (game->lvlitems[dlevel]&(1 << li_mcguffin));
1817
1818 default:
1819
2/4
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 337472 times.
337472 if(it>=0&&it<MAXLEVELS)
1820 {
1821 337472 return (game->lvlitems[it]&(1 << li_mcguffin));
1822 }
1823
1824 break;
1825 }
1826
1827 return 0;
1828 }
1829
1830 case itype_map: //it: -2=any, -1=current level, other=that level
1831 {
1832
2/3
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 29967419 times.
30509045 switch(it)
1833 {
1834 case -2:
1835 {
1836 for(int32_t i=0; i<MAXLEVELS; i++)
1837 {
1838 if(game->lvlitems[i]&(1 << li_map))
1839 {
1840 return true;
1841 }
1842 }
1843
1844 return false;
1845 }
1846
1847 case -1:
1848 29967419 return (game->lvlitems[dlevel]&(1 << li_map))!=0;
1849
1850 default:
1851
2/4
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 541626 times.
541626 if(it>=0&&it<MAXLEVELS)
1852 {
1853 541626 return (game->lvlitems[it]&(1 << li_map))!=0;
1854 }
1855
1856 break;
1857 }
1858
1859 return 0;
1860 }
1861
1862 case itype_compass: //it: -2=any, -1=current level, other=that level
1863 {
1864
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 10090004 times.
10090004 switch(it)
1865 {
1866 case -2:
1867 {
1868 for(int32_t i=0; i<MAXLEVELS; i++)
1869 {
1870 if(game->lvlitems[i]&(1 << li_compass))
1871 {
1872 return true;
1873 }
1874 }
1875
1876 return false;
1877 }
1878
1879 case -1:
1880 10090004 return (game->lvlitems[dlevel]&(1 << li_compass))!=0;
1881
1882 default:
1883 if(it>=0&&it<MAXLEVELS)
1884 {
1885 return (game->lvlitems[it]&(1 << li_compass))!=0;
1886 }
1887
1888 break;
1889 }
1890 return 0;
1891 }
1892
1893 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1894 {
1895
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 206277 times.
206277 switch(it)
1896 {
1897 case -2:
1898 {
1899 for(int32_t i=0; i<MAXLEVELS; i++)
1900 {
1901 if(game->lvlitems[i]&(1 << li_boss_key))
1902 {
1903 return true;
1904 }
1905 }
1906
1907 return false;
1908 }
1909
1910 case -1:
1911 206277 return (game->lvlitems[dlevel]&(1 << li_boss_key))?1:0;
1912
1913 default:
1914 if(it>=0&&it<MAXLEVELS)
1915 {
1916 return (game->lvlitems[it]&(1 << li_boss_key))?1:0;
1917 }
1918 break;
1919 }
1920 return 0;
1921 }
1922
1923 default:
1924 int32_t itemid = getItemID(itemsbuf, item_type, it);
1925
1926 if(itemid == -1)
1927 return false;
1928
1929 return game->get_item(itemid);
1930 }
1931 45770965 }
1932
1933 157325393 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1934 {
1935
9/9
✓ Branch 0 taken 4628167 times.
✓ Branch 1 taken 120300057 times.
✓ Branch 2 taken 4628167 times.
✓ Branch 3 taken 4628167 times.
✓ Branch 4 taken 4628167 times.
✓ Branch 5 taken 4628167 times.
✓ Branch 6 taken 4628167 times.
✓ Branch 7 taken 4628167 times.
✓ Branch 8 taken 4628167 times.
157325393 switch(item_type)
1936 {
1937 case itype_clock:
1938 {
1939 4628167 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1940
1941
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4628167 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4628167 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1942 return itemsbuf[maxid].level;
1943
1944 4628167 return has_item(itype_clock,1) ? 1 : 0;
1945 }
1946
1947 case itype_key:
1948 4628167 return game->get_keys();
1949
1950 case itype_lkey:
1951 4628167 return game->lvlkeys[get_dlevel()];
1952
1953 case itype_magiccontainer:
1954 4628167 return game->get_maxmagic()/game->get_mp_per_block();
1955
1956 case itype_triforcepiece:
1957 {
1958 4628167 int count=0;
1959
1960
2/2
✓ Branch 0 taken 2369621504 times.
✓ Branch 1 taken 4628167 times.
2374249671 for(int i=0; i<MAXLEVELS; i++)
1961 {
1962 2369621504 count+=(game->lvlitems[i]&(1 << li_mcguffin))?1:0;
1963 2369621504 }
1964
1965 4628167 return count;
1966 }
1967
1968 case itype_map:
1969 {
1970 4628167 int count=0;
1971
1972
2/2
✓ Branch 0 taken 2369621504 times.
✓ Branch 1 taken 4628167 times.
2374249671 for(int i=0; i<MAXLEVELS; i++)
1973 {
1974 2369621504 count+=(game->lvlitems[i]&(1 << li_map))?1:0;
1975 2369621504 }
1976
1977 4628167 return count;
1978 }
1979
1980 case itype_compass:
1981 {
1982 4628167 int count=0;
1983
1984
2/2
✓ Branch 0 taken 2369621504 times.
✓ Branch 1 taken 4628167 times.
2374249671 for(int i=0; i<MAXLEVELS; i++)
1985 {
1986 2369621504 count+=(game->lvlitems[i]&(1 << li_compass))?1:0;
1987 2369621504 }
1988
1989 4628167 return count;
1990 }
1991
1992 case itype_bosskey:
1993 {
1994 4628167 int count=0;
1995
1996
2/2
✓ Branch 0 taken 2369621504 times.
✓ Branch 1 taken 4628167 times.
2374249671 for(int i=0; i<MAXLEVELS; i++)
1997 {
1998 2369621504 count+=(game->lvlitems[i]&(1 << li_boss_key))?1:0;
1999 2369621504 }
2000
2001 4628167 return count;
2002 }
2003
2004 default:
2005 120300057 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2006
2007
2/2
✓ Branch 0 taken 85925739 times.
✓ Branch 1 taken 34374318 times.
120300057 if(maxid == -1)
2008 85925739 return 0;
2009
2010 34374318 return itemsbuf[maxid].level;
2011 }
2012 157325393 }
2013
2014 427 std::map<int32_t, int32_t> itemcache;
2015 427 std::map<int32_t, int32_t> itemcache_cost;
2016
2017 void removeFromItemCache(int32_t itemclass)
2018 {
2019 itemcache.erase(itemclass);
2020 itemcache_cost.erase(itemclass);
2021 cache_tile_mod_clear();
2022 }
2023
2024 13273719 void flushItemCache(bool justcost)
2025 {
2026 13273719 itemcache_cost.clear();
2027
2/2
✓ Branch 0 taken 13196376 times.
✓ Branch 1 taken 77343 times.
13273719 if(!justcost)
2028 77343 itemcache.clear();
2029
2/2
✓ Branch 0 taken 6357348 times.
✓ Branch 1 taken 6839028 times.
13196376 else if(replay_version_check(0,19))
2030 6357348 return;
2031
2032 6916371 cache_tile_mod_clear();
2033
2034 //also fix the active subscreen if items were deleted -DD
2035
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6916371 times.
6916371 if(game != NULL)
2036 {
2037 6916371 verifyBothWeapons();
2038 6916371 refresh_subscr_items();
2039 6916371 }
2040 13273719 }
2041
2042 // This is used often, so it should be as direct as possible.
2043 3187207851 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2044 {
2045 3187207851 bool use_cost_cache = replay_version_check(19);
2046
2/2
✓ Branch 0 taken 3043443035 times.
✓ Branch 1 taken 143764816 times.
3187207851 if(jinx_check)
2047 {
2048 //special case for shields...
2049
3/4
✓ Branch 0 taken 56409667 times.
✓ Branch 1 taken 87355149 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 56409667 times.
143764816 if (itemtype == itype_shield && !HeroShieldClk())
2050 56409667 jinx_check = false;
2051
4/4
✓ Branch 0 taken 54225269 times.
✓ Branch 1 taken 33129880 times.
✓ Branch 2 taken 10934448 times.
✓ Branch 3 taken 43290821 times.
87355149 else if(!(HeroSwordClk() || HeroItemClk()))
2052 43290821 jinx_check = false; //not jinxed
2053 143764816 }
2054
4/4
✓ Branch 0 taken 121490 times.
✓ Branch 1 taken 3187086361 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 119637 times.
3187207851 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2055 3187088214 check_bunny = false;
2056
2/2
✓ Branch 0 taken 3127300183 times.
✓ Branch 1 taken 59907668 times.
3187207851 if(itemtype == itype_ring) checkmagic = true;
2057
4/4
✓ Branch 0 taken 3143143523 times.
✓ Branch 1 taken 44064328 times.
✓ Branch 2 taken 310572548 times.
✓ Branch 3 taken 25152461 times.
3522932860 if (!jinx_check && !check_bunny
2058
4/4
✓ Branch 0 taken 3143051494 times.
✓ Branch 1 taken 92029 times.
✓ Branch 2 taken 335725009 times.
✓ Branch 3 taken 2807326485 times.
3143143523 && (use_cost_cache || itemtype != itype_ring))
2059 {
2060
4/4
✓ Branch 0 taken 613715718 times.
✓ Branch 1 taken 2504183315 times.
✓ Branch 2 taken 260092074 times.
✓ Branch 3 taken 353623644 times.
3117899033 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2061 3117899033 auto res = cache.find(itemtype);
2062
2063
2/2
✓ Branch 0 taken 2960822882 times.
✓ Branch 1 taken 157076151 times.
3117899033 if(res != cache.end())
2064 2960822882 return res->second;
2065 157076151 }
2066
2067 226384969 int result = -1;
2068 226384969 int highestlevel = -1;
2069
2070
2/2
✓ Branch 0 taken 57954552064 times.
✓ Branch 1 taken 226384969 times.
58180937033 for(int i=0; i<MAXITEMS; i++)
2071 {
2072
6/6
✓ Branch 0 taken 6338020401 times.
✓ Branch 1 taken 51616531663 times.
✓ Branch 2 taken 97938805 times.
✓ Branch 3 taken 6240081596 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 97856757 times.
57954552064 if(game->get_item(i) && itemsbuf[i].type==itemtype && !item_disabled(i))
2073 {
2074
4/4
✓ Branch 0 taken 93097357 times.
✓ Branch 1 taken 4759400 times.
✓ Branch 2 taken 2473305 times.
✓ Branch 3 taken 90624052 times.
97856757 if(checkmagic && itemtype != itype_magicring)
2075
2/2
✓ Branch 0 taken 90620209 times.
✓ Branch 1 taken 3843 times.
90624052 if(!checkmagiccost(i))
2076 3843 continue;
2077
6/6
✓ Branch 0 taken 90363691 times.
✓ Branch 1 taken 7489223 times.
✓ Branch 2 taken 1259466 times.
✓ Branch 3 taken 6229757 times.
✓ Branch 4 taken 4066789 times.
✓ Branch 5 taken 3422434 times.
97852914 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2078
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3422434 times.
3422434 if(!(itemsbuf[i].flags & item_jinx_immune))
2079 3422434 continue;
2080
3/4
✓ Branch 0 taken 96967 times.
✓ Branch 1 taken 94333513 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96967 times.
94430480 if(check_bunny && !checkbunny(i))
2081 96967 continue;
2082
2083
2/2
✓ Branch 0 taken 8703571 times.
✓ Branch 1 taken 85629942 times.
94333513 if(itemsbuf[i].level >= highestlevel)
2084 {
2085 85629942 highestlevel = itemsbuf[i].level;
2086 85629942 result=i;
2087 85629942 }
2088 94333513 }
2089 57951028820 }
2090
2091
4/4
✓ Branch 0 taken 182320641 times.
✓ Branch 1 taken 44064328 times.
✓ Branch 2 taken 92029 times.
✓ Branch 3 taken 182228612 times.
226384969 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2092 {
2093
2/2
✓ Branch 0 taken 140460625 times.
✓ Branch 1 taken 41767987 times.
182228612 if (use_cost_cache)
2094 {
2095
2/2
✓ Branch 0 taken 122963870 times.
✓ Branch 1 taken 17496755 times.
140460625 if (!checkmagic)
2096 17496755 itemcache[itemtype] = result;
2097
6/6
✓ Branch 0 taken 17496755 times.
✓ Branch 1 taken 122963870 times.
✓ Branch 2 taken 738580 times.
✓ Branch 3 taken 16758175 times.
✓ Branch 4 taken 723432 times.
✓ Branch 5 taken 15148 times.
140460625 if (checkmagic || result < 0 || checkmagiccost(result))
2098 140445477 itemcache_cost[itemtype] = result;
2099 140460625 }
2100 else
2101 {
2102 41767987 itemcache[itemtype] = result;
2103 }
2104 182228612 }
2105 226384969 return result;
2106 3187207851 }
2107
2108 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2109 3160471334 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2110 {
2111
3/4
✓ Branch 0 taken 3143648051 times.
✓ Branch 1 taken 16823283 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3143648051 times.
3160471334 if(itype < 0 || itype >= itype_max) return -1;
2112
1/2
✓ Branch 0 taken 3143648051 times.
✗ Branch 1 not taken.
3143648051 if(game->OverrideItems[itype] > -2)
2113 {
2114 auto ovid = game->OverrideItems[itype];
2115 if(ovid < 0 || ovid >= MAXITEMS)
2116 return -1;
2117 if(itemsbuf[ovid].type == itype)
2118 {
2119 if(itype == itype_magicring)
2120 checkmagic = false;
2121 else if(itype == itype_ring)
2122 checkmagic = true;
2123
2124 if(checkmagic && !checkmagiccost(ovid))
2125 return -1;
2126
2127 if (jinx_check && !checkitem_jinx(ovid))
2128 {
2129 return -1;
2130 }
2131 return ovid;
2132 }
2133 }
2134 3143648051 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2135
2/2
✓ Branch 0 taken 100205016 times.
✓ Branch 1 taken 3043443035 times.
3143648051 if(!jinx_check) //If not already a jinx-immune-only check...
2136 {
2137 //And the player IS jinxed...
2138
2/2
✓ Branch 0 taken 2999883235 times.
✓ Branch 1 taken 43559800 times.
3043443035 if(HeroIsJinxed())
2139 {
2140 //Then do a jinx-immune-only check here
2141 43559800 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2142 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2143 //Should NOT need a compat rule, as this should always return -1 in old quests.
2144
2/2
✓ Branch 0 taken 3185572 times.
✓ Branch 1 taken 40374228 times.
43559800 if(ret2 > -1) return ret2;
2145 40374228 }
2146 3040257463 }
2147 3140462479 return ret;
2148 3160471334 }
2149
2150 70700359 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2151 {
2152 70700359 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2153
2/2
✓ Branch 0 taken 37336744 times.
✓ Branch 1 taken 33363615 times.
70700359 return (result<0) ? 0 : itemsbuf[result].power;
2154 }
2155
2156 30 int32_t heart_container_id()
2157 {
2158
1/2
✓ Branch 0 taken 870 times.
✗ Branch 1 not taken.
870 for(int32_t i=0; i<MAXITEMS; i++)
2159 {
2160
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 840 times.
870 if(itemsbuf[i].type == itype_heartcontainer)
2161 {
2162 30 return i;
2163 }
2164 840 }
2165 return -1;
2166 30 }
2167
2168 struct tilemod_cache_state_t
2169 {
2170
6/6
✓ Branch 0 taken 4627811 times.
✓ Branch 1 taken 8991962 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8991960 times.
✓ Branch 4 taken 354 times.
✓ Branch 5 taken 8991606 times.
22611735 bool operator==(const tilemod_cache_state_t&) const = default;
2171
2172 bool valid;
2173 bool bunny_clock;
2174 bool superman;
2175 int shield;
2176 };
2177 tilemod_cache_state_t tilemod_cache_state;
2178 int32_t tilemod_cache_value;
2179
2180 6917968 void cache_tile_mod_clear()
2181 {
2182 6917968 tilemod_cache_state = {false};
2183 6917968 }
2184
2185 13619773 int32_t item_tile_mod()
2186 {
2187 54479092 tilemod_cache_state_t state = {
2188 .valid = true,
2189 13619773 .bunny_clock = Hero.BunnyClock() != 0,
2190 13619773 .superman = Hero.superman,
2191 13619773 .shield = Hero.active_shield_id,
2192 };
2193
2/2
✓ Branch 0 taken 8991606 times.
✓ Branch 1 taken 4628167 times.
13619773 if (tilemod_cache_state == state)
2194 8991606 return tilemod_cache_value;
2195
2196 4628167 int32_t tile=0;
2197 4628167 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2198
4/4
✓ Branch 0 taken 4008000 times.
✓ Branch 1 taken 620167 times.
✓ Branch 2 taken 3079194 times.
✓ Branch 3 taken 928806 times.
4628167 if(check_bombcost || game->get_bombs())
2199 {
2200 3699361 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2201
3/4
✓ Branch 0 taken 3639680 times.
✓ Branch 1 taken 59681 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3639680 times.
3699361 if(itemid > -1 && checkbunny(itemid))
2202 3639680 tile+=itemsbuf[itemid].ltm;
2203 3699361 }
2204
2205
4/4
✓ Branch 0 taken 4008000 times.
✓ Branch 1 taken 620167 times.
✓ Branch 2 taken 965298 times.
✓ Branch 3 taken 3042702 times.
4628167 if(check_bombcost || game->get_sbombs())
2206 {
2207 1585465 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2208
3/4
✓ Branch 0 taken 976704 times.
✓ Branch 1 taken 608761 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 976704 times.
1585465 if(itemid > -1 && checkbunny(itemid))
2209 976704 tile+=itemsbuf[itemid].ltm;
2210 1585465 }
2211
2212
2/2
✓ Branch 0 taken 4615318 times.
✓ Branch 1 taken 12849 times.
4628167 if(current_item(itype_clock))
2213 {
2214 12849 int32_t itemid =
2215
2/2
✓ Branch 0 taken 12704 times.
✓ Branch 1 taken 145 times.
12849 get_qr(qr_HARDCODED_LITEM_LTMS)
2216 ? iClock
2217 145 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2218
2/4
✓ Branch 0 taken 12849 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12849 times.
12849 if(itemid > -1 && checkbunny(itemid))
2219 12849 tile+=itemsbuf[itemid].ltm;
2220 12849 }
2221
2222
2/2
✓ Branch 0 taken 3982525 times.
✓ Branch 1 taken 645642 times.
4628167 if(current_item(itype_key))
2223 {
2224 645642 int32_t itemid =
2225
2/2
✓ Branch 0 taken 608640 times.
✓ Branch 1 taken 37002 times.
645642 get_qr(qr_HARDCODED_LITEM_LTMS)
2226 ? iKey
2227 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2228
2/4
✓ Branch 0 taken 645642 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 645642 times.
645642 if(itemid > -1 && checkbunny(itemid))
2229 645642 tile+=itemsbuf[itemid].ltm;
2230 645642 }
2231
2232
2/2
✓ Branch 0 taken 4070630 times.
✓ Branch 1 taken 557537 times.
4628167 if(current_item(itype_lkey))
2233 {
2234 557537 int32_t itemid =
2235
2/2
✓ Branch 0 taken 414169 times.
✓ Branch 1 taken 143368 times.
557537 get_qr(qr_HARDCODED_LITEM_LTMS)
2236 ? iLevelKey
2237 143368 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2238
2/4
✓ Branch 0 taken 557537 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 557537 times.
557537 if(itemid > -1 && checkbunny(itemid))
2239 557537 tile+=itemsbuf[itemid].ltm;
2240 557537 }
2241
2242
2/2
✓ Branch 0 taken 1586486 times.
✓ Branch 1 taken 3041681 times.
4628167 if(current_item(itype_map))
2243 {
2244 3041681 int32_t itemid =
2245
2/2
✓ Branch 0 taken 2823834 times.
✓ Branch 1 taken 217847 times.
3041681 get_qr(qr_HARDCODED_LITEM_LTMS)
2246 ? iMap
2247 217847 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2248
2/4
✓ Branch 0 taken 3041681 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3041681 times.
3041681 if(itemid > -1 && checkbunny(itemid))
2249 3041681 tile+=itemsbuf[itemid].ltm;
2250 3041681 }
2251
2252
2/2
✓ Branch 0 taken 2121202 times.
✓ Branch 1 taken 2506965 times.
4628167 if(current_item(itype_compass))
2253 {
2254 2506965 int32_t itemid =
2255
2/2
✓ Branch 0 taken 2295941 times.
✓ Branch 1 taken 211024 times.
2506965 get_qr(qr_HARDCODED_LITEM_LTMS)
2256 ? iCompass
2257 211024 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2258
2/4
✓ Branch 0 taken 2506965 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2506965 times.
2506965 if(itemid > -1 && checkbunny(itemid))
2259 2506965 tile+=itemsbuf[itemid].ltm;
2260 2506965 }
2261
2262
2/2
✓ Branch 0 taken 1346799 times.
✓ Branch 1 taken 3281368 times.
4628167 if(current_item(itype_bosskey))
2263 {
2264 3281368 int32_t itemid =
2265
2/2
✓ Branch 0 taken 2993139 times.
✓ Branch 1 taken 288229 times.
3281368 get_qr(qr_HARDCODED_LITEM_LTMS)
2266 ? iBossKey
2267 288229 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2268
2/4
✓ Branch 0 taken 3281368 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3281368 times.
3281368 if(itemid > -1 && checkbunny(itemid))
2269 3281368 tile+=itemsbuf[itemid].ltm;
2270 3281368 }
2271
2272
2/2
✓ Branch 0 taken 48322 times.
✓ Branch 1 taken 4579845 times.
4628167 if(current_item(itype_magiccontainer))
2273 {
2274 4579845 int32_t itemid =
2275
2/2
✓ Branch 0 taken 3904336 times.
✓ Branch 1 taken 675509 times.
4579845 get_qr(qr_HARDCODED_LITEM_LTMS)
2276 ? iMagicC
2277 675509 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2278
3/4
✓ Branch 0 taken 4579845 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4579828 times.
4579845 if(itemid > -1 && checkbunny(itemid))
2279 4579828 tile+=itemsbuf[itemid].ltm;
2280 4579845 }
2281
2282
2/2
✓ Branch 0 taken 1328809 times.
✓ Branch 1 taken 3299358 times.
4628167 if(current_item(itype_triforcepiece))
2283 {
2284 3299358 int32_t itemid =
2285
2/2
✓ Branch 0 taken 3069478 times.
✓ Branch 1 taken 229880 times.
3299358 get_qr(qr_HARDCODED_LITEM_LTMS)
2286 ? iTriforce
2287 229880 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2288
2/4
✓ Branch 0 taken 3299358 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3299358 times.
3299358 if(itemid > -1 && checkbunny(itemid))
2289 3299358 tile+=itemsbuf[itemid].ltm;
2290 3299358 }
2291
2292
2/2
✓ Branch 0 taken 2369621504 times.
✓ Branch 1 taken 4628167 times.
2374249671 for(int32_t i=0; i<itype_max; i++)
2293 {
2294
2/2
✓ Branch 0 taken 2023628800 times.
✓ Branch 1 taken 345992704 times.
2369621504 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2295 {
2296
2/2
✓ Branch 0 taken 6757670 times.
✓ Branch 1 taken 339235034 times.
345992704 switch(i)
2297 {
2298 case itype_bomb:
2299 case itype_sbomb:
2300 case itype_clock:
2301 case itype_key:
2302 case itype_lkey:
2303 case itype_map:
2304 case itype_compass:
2305 case itype_bosskey:
2306 case itype_magiccontainer:
2307 case itype_triforcepiece:
2308 6757670 continue; //already handled
2309 }
2310 339235034 }
2311 2362863834 int32_t itemid = current_item_id(i,false);
2312
2/2
✓ Branch 0 taken 2358235667 times.
✓ Branch 1 taken 4628167 times.
2362863834 if(i == itype_shield)
2313 4628167 itemid = getCurrentShield(false);
2314
2315
4/4
✓ Branch 0 taken 119496253 times.
✓ Branch 1 taken 2243367581 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 119496252 times.
2362863834 if(itemid < 0 || !checkbunny(itemid))
2316 2243367582 continue;
2317
2318 119496252 itemdata const& itm = itemsbuf[itemid];
2319
2320
2/2
✓ Branch 0 taken 115589232 times.
✓ Branch 1 taken 3907020 times.
119496252 switch(itm.type)
2321 {
2322 case itype_shield:
2323
1/2
✓ Branch 0 taken 3907020 times.
✗ Branch 1 not taken.
3907020 if(itm.flags & item_flag9) //active shield
2324 {
2325 if(!usingActiveShield(itemid))
2326 {
2327 tile+=itm.misc6; //'Inactive PTM'
2328 continue;
2329 }
2330 }
2331 3907020 break;
2332 }
2333
2334 119496252 tile+=itm.ltm;
2335 119496252 }
2336
2337 4628167 tilemod_cache_value = tile;
2338 4628167 tilemod_cache_state = state;
2339 4628167 return tile;
2340 13619773 }
2341
2342 13619773 int32_t bunny_tile_mod()
2343 {
2344
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 13617903 times.
13619773 if(Hero.BunnyClock())
2345 {
2346 1870 return game->get_bunny_ltm();
2347 }
2348 13617903 return 0;
2349 13619773 }
2350
2351 // Hints are drawn on a separate layer to combo reveals.
2352 // TODO: move out of zc_sys.cpp, weird place for this code.
2353 20058 void draw_lens_under(BITMAP *dest, bool layer)
2354 {
2355 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2356 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2357 //Lens flag 3: Don't show armos/chest/dive items
2358 //Lens flag 4: Show Raft Paths
2359 //Lens flag 5: Show Invisible Enemies
2360
4/4
✓ Branch 0 taken 19602 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 9801 times.
✓ Branch 3 taken 9801 times.
20058 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2361
2362 20058 int32_t strike_hint_table[11]=
2363 {
2364 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2365 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2366 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2367 };
2368
2369 {
2370 20058 int32_t blink_rate=flash_reduction_enabled()?6:1;
2371 20058 int32_t tempitem, tempweapon=0;
2372 20058 strike_hint=strike_hint_table[strike_hint_counter];
2373
2374
2/2
✓ Branch 0 taken 19459 times.
✓ Branch 1 taken 599 times.
20058 if(strike_hint_timer>32)
2375 {
2376 599 strike_hint_timer=0;
2377 599 strike_hint_counter=((strike_hint_counter+1)%11);
2378 599 }
2379
2380 20058 ++strike_hint_timer;
2381
2382 3550266 for_every_visible_rpos_layer0([&](const rpos_handle_t& rpos_handle) {
2383 3530208 mapscr* scr = rpos_handle.scr;
2384 7306676 auto [x, y] = rpos_handle.xy();
2385 7060416 y += playing_field_offset;
2386
2387 3530208 int32_t tempitemx=-16, tempitemy=-16;
2388 3530208 int32_t tempweaponx=-16, tempweapony=-16;
2389
2390
2/2
✓ Branch 0 taken 7060416 times.
✓ Branch 1 taken 3530208 times.
10590624 for(int32_t iter=0; iter<2; ++iter)
2391 {
2392 7060416 int32_t checkflag=0;
2393
2394
2/2
✓ Branch 0 taken 3530208 times.
✓ Branch 1 taken 3530208 times.
7060416 if(iter==0)
2395 {
2396 3530208 checkflag = rpos_handle.cflag();
2397 3530208 }
2398 else
2399 {
2400 3530208 checkflag = rpos_handle.sflag();
2401 }
2402
2403
2/2
✓ Branch 0 taken 7059318 times.
✓ Branch 1 taken 1098 times.
7060416 if(checkflag==mfSTRIKE)
2404 {
2405
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2406 {
2407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSTRIKE],scr->secretcset[sSTRIKE]);
2408 906 }
2409 else
2410 {
2411 192 checkflag = strike_hint;
2412 }
2413 1098 }
2414
2415
21/36
✓ Branch 0 taken 6911766 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7060416 switch(checkflag)
2416 {
2417 case 0:
2418 case mfZELDA:
2419 case mfPUSHED:
2420 case mfENEMY0:
2421 case mfENEMY1:
2422 case mfENEMY2:
2423 case mfENEMY3:
2424 case mfENEMY4:
2425 case mfENEMY5:
2426 case mfENEMY6:
2427 case mfENEMY7:
2428 case mfENEMY8:
2429 case mfENEMY9:
2430 case mfSINGLE:
2431 case mfSINGLE16:
2432 case mfNOENEMY:
2433 case mfTRAP_H:
2434 case mfTRAP_V:
2435 case mfTRAP_4:
2436 case mfTRAP_LR:
2437 case mfTRAP_UD:
2438 case mfNOGROUNDENEMY:
2439 case mfNOBLOCKS:
2440 case mfSCRIPT1:
2441 case mfSCRIPT2:
2442 case mfSCRIPT3:
2443 case mfSCRIPT4:
2444 case mfSCRIPT5:
2445 case mfSCRIPT6:
2446 case mfSCRIPT7:
2447 case mfSCRIPT8:
2448 case mfSCRIPT9:
2449 case mfSCRIPT10:
2450 case mfSCRIPT11:
2451 case mfSCRIPT12:
2452 case mfSCRIPT13:
2453 case mfSCRIPT14:
2454 case mfSCRIPT15:
2455 case mfSCRIPT16:
2456 case mfSCRIPT17:
2457 case mfSCRIPT18:
2458 case mfSCRIPT19:
2459 case mfSCRIPT20:
2460 case mfPITHOLE:
2461 case mfPITFALLFLOOR:
2462 case mfLAVA:
2463 case mfICE:
2464 case mfICEDAMAGE:
2465 case mfDAMAGE1:
2466 case mfDAMAGE2:
2467 case mfDAMAGE4:
2468 case mfDAMAGE8:
2469 case mfDAMAGE16:
2470 case mfDAMAGE32:
2471 case mfFREEZEALL:
2472 case mfFREZEALLANSFFCS:
2473 case mfFREEZEFFCSOLY:
2474 case mfSCRITPTW1TRIG:
2475 case mfSCRITPTW2TRIG:
2476 case mfSCRITPTW3TRIG:
2477 case mfSCRITPTW4TRIG:
2478 case mfSCRITPTW5TRIG:
2479 case mfSCRITPTW6TRIG:
2480 case mfSCRITPTW7TRIG:
2481 case mfSCRITPTW8TRIG:
2482 case mfSCRITPTW9TRIG:
2483 case mfSCRITPTW10TRIG:
2484 case mfTROWEL:
2485 case mfTROWELNEXT:
2486 case mfTROWELSPECIALITEM:
2487 case mfSLASHPOT:
2488 case mfLIFTPOT:
2489 case mfLIFTORSLASH:
2490 case mfLIFTROCK:
2491 case mfLIFTROCKHEAVY:
2492 case mfDROPITEM:
2493 case mfSPECIALITEM:
2494 case mfDROPKEY:
2495 case mfDROPLKEY:
2496 case mfDROPCOMPASS:
2497 case mfDROPMAP:
2498 case mfDROPBOSSKEY:
2499 case mfSPAWNNPC:
2500 case mfSWITCHHOOK:
2501 case mfSIDEVIEWLADDER:
2502 case mfSIDEVIEWPLATFORM:
2503 case mfNOENEMYSPAWN:
2504 case mfENEMYALL:
2505 case mfNOMIRROR:
2506 case mfUNSAFEGROUND:
2507 case mf168:
2508 case mf169:
2509 case mf170:
2510 case mf171:
2511 case mf172:
2512 case mf173:
2513 case mf174:
2514 case mf175:
2515 case mf176:
2516 case mf177:
2517 case mf178:
2518 case mf179:
2519 case mf180:
2520 case mf181:
2521 case mf182:
2522 case mf183:
2523 case mf184:
2524 case mf185:
2525 case mf186:
2526 case mf187:
2527 case mf188:
2528 case mf189:
2529 case mf190:
2530 case mf191:
2531 case mf192:
2532 case mf193:
2533 case mf194:
2534 case mf195:
2535 case mf196:
2536 case mf197:
2537 case mf198:
2538 case mf199:
2539 case mf200:
2540 case mf201:
2541 case mf202:
2542 case mf203:
2543 case mf204:
2544 case mf205:
2545 case mf206:
2546 case mf207:
2547 case mf208:
2548 case mf209:
2549 case mf210:
2550 case mf211:
2551 case mf212:
2552 case mf213:
2553 case mf214:
2554 case mf215:
2555 case mf216:
2556 case mf217:
2557 case mf218:
2558 case mf219:
2559 case mf220:
2560 case mf221:
2561 case mf222:
2562 case mf223:
2563 case mf224:
2564 case mf225:
2565 case mf226:
2566 case mf227:
2567 case mf228:
2568 case mf229:
2569 case mf230:
2570 case mf231:
2571 case mf232:
2572 case mf233:
2573 case mf234:
2574 case mf235:
2575 case mf236:
2576 case mf237:
2577 case mf238:
2578 case mf239:
2579 case mf240:
2580 case mf241:
2581 case mf242:
2582 case mf243:
2583 case mf244:
2584 case mf245:
2585 case mf246:
2586 case mf247:
2587 case mf248:
2588 case mf249:
2589 case mf250:
2590 case mf251:
2591 case mf252:
2592 case mf253:
2593 case mf254:
2594 case mfEXTENDED:
2595 6911766 break;
2596
2597 case mfPUSHUD:
2598 case mfPUSHLR:
2599 case mfPUSH4:
2600 case mfPUSHU:
2601 case mfPUSHD:
2602 case mfPUSHL:
2603 case mfPUSHR:
2604 case mfPUSHUDNS:
2605 case mfPUSHLRNS:
2606 case mfPUSH4NS:
2607 case mfPUSHUNS:
2608 case mfPUSHDNS:
2609 case mfPUSHLNS:
2610 case mfPUSHRNS:
2611 case mfPUSHUDINS:
2612 case mfPUSHLRINS:
2613 case mfPUSH4INS:
2614 case mfPUSHUINS:
2615 case mfPUSHDINS:
2616 case mfPUSHLINS:
2617 case mfPUSHRINS:
2618
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2619
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2620 {
2621 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->undercombo,scr->undercset);
2622 }
2623
2624
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2625
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2626 {
2627
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2628 {
2629
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch (rpos_handle.ctype())
2630 {
2631 case cPUSH_HEAVY:
2632 case cPUSH_HW:
2633 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2634 144 tempitemx=x, tempitemy=y;
2635
2636
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(tempitem>-1)
2637 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2638
2639 72 break;
2640
2641 case cPUSH_HEAVY2:
2642 case cPUSH_HW2:
2643 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2644 126 tempitemx=x, tempitemy=y;
2645
2646
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
63 if(tempitem>-1)
2647 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2648
2649 63 break;
2650 }
2651 1032 }
2652 2520 }
2653
2654 3258 break;
2655
2656 case mfWHISTLE:
2657
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2658 {
2659 tempitem=getItemID(itemsbuf,itype_whistle,1);
2660
2661 if(tempitem<0) break;
2662
2663 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2664 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2665 {
2666 tempitemx=x;
2667 tempitemy=y;
2668 }
2669
2670 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2671 }
2672
2673 2418 break;
2674
2675 //Why is this here?
2676 case mfFAIRY:
2677 case mfMAGICFAIRY:
2678 case mfALLFAIRY:
2679 if(hints)
2680 {
2681 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2682
2683 if(tempitem < 0) break;
2684
2685 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2686 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2687 {
2688 tempitemx=x;
2689 tempitemy=y;
2690 }
2691
2692 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2693 }
2694
2695 break;
2696
2697 case mfANYFIRE:
2698
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2699 {
2700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBCANDLE],scr->secretcset[sBCANDLE]);
2701 252 }
2702 else
2703 {
2704 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2705
2706
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2707
2708
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2709
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2710 {
2711 189 tempitemx=x;
2712 189 tempitemy=y;
2713 189 }
2714
2715 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2716 }
2717
2718 504 break;
2719
2720 case mfSTRONGFIRE:
2721 if(!hints)
2722 {
2723 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sRCANDLE],scr->secretcset[sRCANDLE]);
2724 }
2725 else
2726 {
2727 tempitem=getItemID(itemsbuf,itype_candle,2);
2728
2729 if(tempitem<0) break;
2730
2731 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2732 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2733 {
2734 tempitemx=x;
2735 tempitemy=y;
2736 }
2737
2738 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2739 }
2740
2741 break;
2742
2743 case mfMAGICFIRE:
2744 if(!hints)
2745 {
2746 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDFIRE],scr->secretcset[sWANDFIRE]);
2747 }
2748 else
2749 {
2750 tempitem=getItemID(itemsbuf,itype_wand,1);
2751
2752 if(tempitem<0) break;
2753
2754 tempweapon=wFire;
2755
2756 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2757 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2758 {
2759 tempitemx=x;
2760 tempitemy=y;
2761 }
2762 else
2763 {
2764 tempweaponx=x;
2765 tempweapony=y;
2766 }
2767
2768 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2769 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2770 }
2771
2772 break;
2773
2774 case mfDIVINEFIRE:
2775 if(!hints)
2776 {
2777 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sDIVINEFIRE],scr->secretcset[sDIVINEFIRE]);
2778 }
2779 else
2780 {
2781 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2782
2783 if(tempitem<0) break;
2784
2785 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2786 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2787 {
2788 tempitemx=x;
2789 tempitemy=y;
2790 }
2791
2792 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2793 }
2794
2795 break;
2796
2797 case mfARROW:
2798
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2799 {
2800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sARROW],scr->secretcset[sARROW]);
2801 732 }
2802 else
2803 {
2804 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2805
2806
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2807
2808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2809
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2810 {
2811 61 tempitemx=x;
2812 61 tempitemy=y;
2813 61 }
2814
2815 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2816 }
2817
2818 814 break;
2819
2820 case mfSARROW:
2821 if(!hints)
2822 {
2823 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSARROW],scr->secretcset[sSARROW]);
2824 }
2825 else
2826 {
2827 tempitem=getItemID(itemsbuf,itype_arrow,2);
2828
2829 if(tempitem<0) break;
2830
2831 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2832 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2833 {
2834 tempitemx=x;
2835 tempitemy=y;
2836 }
2837
2838 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2839 }
2840
2841 break;
2842
2843 case mfGARROW:
2844 if(!hints)
2845 {
2846 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sGARROW],scr->secretcset[sGARROW]);
2847 }
2848 else
2849 {
2850 tempitem=getItemID(itemsbuf,itype_arrow,3);
2851
2852 if(tempitem<0) break;
2853
2854 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2855 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2856 {
2857 tempitemx=x;
2858 tempitemy=y;
2859 }
2860
2861 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2862 }
2863
2864 break;
2865
2866 case mfBOMB:
2867
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2868 {
2869
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBOMB],scr->secretcset[sBOMB]);
2870 76 }
2871 else
2872 {
2873 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2874 17 tempweapon = wLitBomb;
2875
2876 //if (tempitem<0) break;
2877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2878
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2879 {
2880 12 tempweaponx=x;
2881 12 tempweapony=y;
2882 12 }
2883
2884 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2885 }
2886
2887 93 break;
2888
2889 case mfSBOMB:
2890
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2891 {
2892
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSBOMB],scr->secretcset[sSBOMB]);
2893 48 }
2894 else
2895 {
2896 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2897 //if (tempitem<0) break;
2898 48 tempweapon = wLitSBomb;
2899
2900
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2901
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2902 {
2903 36 tempweaponx=x;
2904 36 tempweapony=y;
2905 36 }
2906
2907 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2908 }
2909
2910 96 break;
2911
2912 case mfARMOS_SECRET:
2913
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2914 {
2915
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2916 36 putcombo(dest,x,y,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
2917 12 }
2918 24 break;
2919
2920 case mfBRANG:
2921
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2922 {
2923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2924 60 putcombo(dest,x,y,scr->secretcombo[sBRANG],scr->secretcset[sBRANG]);
2925 20 }
2926 else
2927 {
2928 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2929
2930
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2931
2932
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2933
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2934 {
2935 4 tempitemx=x;
2936 4 tempitemy=y;
2937 4 }
2938
2939 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2940 }
2941
2942 25 break;
2943
2944 case mfMBRANG:
2945 if(!hints)
2946 {
2947 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMBRANG],scr->secretcset[sMBRANG]);
2948 }
2949 else
2950 {
2951 tempitem=getItemID(itemsbuf,itype_brang,2);
2952
2953 if(tempitem<0) break;
2954
2955 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2956 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2957 {
2958 tempitemx=x;
2959 tempitemy=y;
2960 }
2961
2962 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2963 }
2964
2965 break;
2966
2967 case mfFBRANG:
2968 if(!hints)
2969 {
2970 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sFBRANG],scr->secretcset[sFBRANG]);
2971 }
2972 else
2973 {
2974 tempitem=getItemID(itemsbuf,itype_brang,3);
2975
2976 if(tempitem<0) break;
2977
2978 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2979 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2980 {
2981 tempitemx=x;
2982 tempitemy=y;
2983 }
2984
2985 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2986 }
2987
2988 break;
2989
2990 case mfWANDMAGIC:
2991
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
2992 {
2993
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDMAGIC],scr->secretcset[sWANDMAGIC]);
2994 138 }
2995 else
2996 {
2997 tempitem=getItemID(itemsbuf,itype_wand,1);
2998
2999 if(tempitem<0) break;
3000
3001 tempweapon=itemsbuf[tempitem].wpn3;
3002
3003 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3004 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3005 {
3006 tempitemx=x;
3007 tempitemy=y;
3008 }
3009 else
3010 {
3011 tempweaponx=x;
3012 tempweapony=y;
3013 --lens_hint_weapon[wMagic][4];
3014
3015 if(lens_hint_weapon[wMagic][4]<-8)
3016 {
3017 lens_hint_weapon[wMagic][4]=8;
3018 }
3019 }
3020
3021 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3022 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3023 }
3024
3025 138 break;
3026
3027 case mfREFMAGIC:
3028
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3029 {
3030 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFMAGIC],scr->secretcset[sREFMAGIC]);
3031 }
3032 else
3033 {
3034 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3035
3036
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3037
3038 16 tempweapon=ewMagic;
3039
3040
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3041
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3042 {
3043 13 tempitemx=x;
3044 13 tempitemy=y;
3045 13 }
3046 else
3047 {
3048 3 tempweaponx=x;
3049 3 tempweapony=y;
3050
3051
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3052 {
3053 1 --lens_hint_weapon[ewMagic][4];
3054 1 }
3055 else
3056 {
3057 2 ++lens_hint_weapon[ewMagic][4];
3058 }
3059
3060
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3061 {
3062 lens_hint_weapon[ewMagic][2]=up;
3063 }
3064
3065
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3066 {
3067 2 lens_hint_weapon[ewMagic][2]=down;
3068 2 }
3069 }
3070
3071 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3072 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3073 }
3074
3075 16 break;
3076
3077 case mfREFFIREBALL:
3078
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3079 {
3080 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFFIREBALL],scr->secretcset[sREFFIREBALL]);
3081 }
3082 else
3083 {
3084 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3085
3086
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3087
3088 16 tempweapon=ewFireball;
3089
3090
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3091
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3092 {
3093 12 tempitemx=x;
3094 12 tempitemy=y;
3095 12 tempweaponx=x;
3096 12 tempweapony=y;
3097 12 ++lens_hint_weapon[ewFireball][3];
3098
3099
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3100 {
3101 1 lens_hint_weapon[ewFireball][3]=-8;
3102 1 lens_hint_weapon[ewFireball][4]=8;
3103 1 }
3104
3105
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3106 {
3107 8 ++lens_hint_weapon[ewFireball][4];
3108 8 }
3109 else
3110 {
3111 4 --lens_hint_weapon[ewFireball][4];
3112 }
3113 12 }
3114
3115 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3116 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3117 }
3118
3119 16 break;
3120
3121 case mfSWORD:
3122
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3123 {
3124 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORD],scr->secretcset[sSWORD]);
3125 }
3126 else
3127 {
3128 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3129
3130
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3131
3132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3133
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3134 {
3135 5 tempitemx=x;
3136 5 tempitemy=y;
3137 5 }
3138
3139 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3140 }
3141
3142 7 break;
3143
3144 case mfWSWORD:
3145 if(!hints)
3146 {
3147 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORD],scr->secretcset[sWSWORD]);
3148 }
3149 else
3150 {
3151 tempitem=getItemID(itemsbuf,itype_sword,2);
3152
3153 if(tempitem<0) break;
3154
3155 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3156 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3157 {
3158 tempitemx=x;
3159 tempitemy=y;
3160 }
3161
3162 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3163 }
3164
3165 break;
3166
3167 case mfMSWORD:
3168 if(!hints)
3169 {
3170 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORD],scr->secretcset[sMSWORD]);
3171 }
3172 else
3173 {
3174 tempitem=getItemID(itemsbuf,itype_sword,3);
3175
3176 if(tempitem<0) break;
3177
3178 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3179 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3180 {
3181 tempitemx=x;
3182 tempitemy=y;
3183 }
3184
3185 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3186 }
3187
3188 break;
3189
3190 case mfXSWORD:
3191 if(!hints)
3192 {
3193 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORD],scr->secretcset[sXSWORD]);
3194 }
3195 else
3196 {
3197 tempitem=getItemID(itemsbuf,itype_sword,4);
3198
3199 if(tempitem<0) break;
3200
3201 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3202 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3203 {
3204 tempitemx=x;
3205 tempitemy=y;
3206 }
3207
3208 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3209 }
3210
3211 break;
3212
3213 case mfSWORDBEAM:
3214
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3215 {
3216 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORDBEAM],scr->secretcset[sSWORDBEAM]);
3217 }
3218 else
3219 {
3220 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3221
3222
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3223
3224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3225
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3226 {
3227 11 tempitemx=x;
3228 11 tempitemy=y;
3229 11 }
3230
3231 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3232 }
3233
3234 16 break;
3235
3236 case mfWSWORDBEAM:
3237 if(!hints)
3238 {
3239 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORDBEAM],scr->secretcset[sWSWORDBEAM]);
3240 }
3241 else
3242 {
3243 tempitem=getItemID(itemsbuf,itype_sword,2);
3244
3245 if(tempitem<0) break;
3246
3247 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3248 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3249 {
3250 tempitemx=x;
3251 tempitemy=y;
3252 }
3253
3254 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3255 }
3256
3257 break;
3258
3259 case mfMSWORDBEAM:
3260 if(!hints)
3261 {
3262 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORDBEAM],scr->secretcset[sMSWORDBEAM]);
3263 }
3264 else
3265 {
3266 tempitem=getItemID(itemsbuf,itype_sword,3);
3267
3268 if(tempitem<0) break;
3269
3270 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3271 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3272 {
3273 tempitemx=x;
3274 tempitemy=y;
3275 }
3276
3277 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3278 }
3279
3280 break;
3281
3282 case mfXSWORDBEAM:
3283 if(!hints)
3284 {
3285 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORDBEAM],scr->secretcset[sXSWORDBEAM]);
3286 }
3287 else
3288 {
3289 tempitem=getItemID(itemsbuf,itype_sword,4);
3290
3291 if(tempitem<0) break;
3292
3293 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3294 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3295 {
3296 tempitemx=x;
3297 tempitemy=y;
3298 }
3299
3300 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3301 }
3302
3303 break;
3304
3305 case mfHOOKSHOT:
3306
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3307 {
3308 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHOOKSHOT],scr->secretcset[sHOOKSHOT]);
3309 }
3310 else
3311 {
3312 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3313
3314
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3315
3316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3317
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3318 {
3319 12 tempitemx=x;
3320 12 tempitemy=y;
3321 12 }
3322
3323 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3324 }
3325
3326 17 break;
3327
3328 case mfWAND:
3329
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3330 {
3331 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWAND],scr->secretcset[sWAND]);
3332 }
3333 else
3334 {
3335 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3336
3337
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3338
3339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3340
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3341 {
3342 28 tempitemx=x;
3343 28 tempitemy=y;
3344 28 }
3345
3346 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3347 }
3348
3349 35 break;
3350
3351 case mfHAMMER:
3352
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3353 {
3354 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHAMMER],scr->secretcset[sHAMMER]);
3355 }
3356 else
3357 {
3358 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3359
3360
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3361
3362
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3363
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3364 {
3365 13 tempitemx=x;
3366 13 tempitemy=y;
3367 13 }
3368
3369 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3370 }
3371
3372 17 break;
3373
3374 case mfARMOS_ITEM:
3375 case mfDIVE_ITEM:
3376 {
3377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
2602 int flag = (cur_screen < 128 && get_qr(qr_ITEMPICKUPSETSBELOW)) ? mITEM : mSPECIALITEM;
3378
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2602 times.
2602 if((!getmapflag(scr, flag) || (scr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3379 {
3380 7806 putitem2(dest,x,y,scr->catchall, lens_hint_item[scr->catchall][0], lens_hint_item[scr->catchall][1], 0);
3381 2602 }
3382 2602 break;
3383 }
3384
3385 case 16:
3386 case 17:
3387 case 18:
3388 case 19:
3389 case 20:
3390 case 21:
3391 case 22:
3392 case 23:
3393 case 24:
3394 case 25:
3395 case 26:
3396 case 27:
3397 case 28:
3398 case 29:
3399 case 30:
3400 case 31:
3401
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3403 323670 putcombo(dest,x,y,scr->secretcombo[checkflag-16+4],scr->secretcset[checkflag-16+4]);
3404
3405 108898 break;
3406 case mfSECRETSNEXT:
3407 if(!hints)
3408 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3409 putcombo(dest,x,y,rpos_handle.data()+1,rpos_handle.cset());
3410
3411 break;
3412
3413 case mfSTRIKE:
3414
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3415 {
3416 906 goto special;
3417 }
3418 else
3419 {
3420 break;
3421 }
3422
3423 28750 default: goto special;
3424
3425 special:
3426
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3427 {
3428
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3429 {
3430 24770 rectfill(dest,x,y,x+15,y+15,WHITE);
3431 4954 }
3432 6604 }
3433
3434 29656 break;
3435 }
3436 7060416 }
3437 3530208 });
3438
3439 40116 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3440 90824 auto [offx, offy] = translate_screen_coordinates_to_world(scr->screen);
3441
3442 40116 offx -= viewport.x;
3443 40116 offy -= viewport.y;
3444 40116 offy += playing_field_offset;
3445
3446
2/2
✓ Branch 0 taken 10029 times.
✓ Branch 1 taken 10029 times.
20058 if (layer)
3447 {
3448
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 359 times.
10029 if (scr->door[0]==dWALK)
3449 1795 rectfill(dest, 120+offx, 16+offy, 135+offx, 31+offy, WHITE);
3450
3451
2/2
✓ Branch 0 taken 9606 times.
✓ Branch 1 taken 423 times.
10029 if (scr->door[1]==dWALK)
3452 2115 rectfill(dest, 120+offx, 144+offy, 135+offx, 159+offy, WHITE);
3453
3454
2/2
✓ Branch 0 taken 9447 times.
✓ Branch 1 taken 582 times.
10029 if (scr->door[2]==dWALK)
3455 2910 rectfill(dest, 16+offx, 80+offy, 31+offx, 95+offy, WHITE);
3456
3457
2/2
✓ Branch 0 taken 9405 times.
✓ Branch 1 taken 624 times.
10029 if (scr->door[3]==dWALK)
3458 3120 rectfill(dest, 224+offx, 80+offy, 239+offx, 95+offy, WHITE);
3459
3460
2/2
✓ Branch 0 taken 9986 times.
✓ Branch 1 taken 43 times.
10029 if (scr->door[0]==dBOMB)
3461 {
3462 129 showbombeddoor(scr, dest, 0, offx, offy);
3463 43 }
3464
3465
2/2
✓ Branch 0 taken 9990 times.
✓ Branch 1 taken 39 times.
10029 if (scr->door[1]==dBOMB)
3466 {
3467 117 showbombeddoor(scr, dest, 1, offx, offy);
3468 39 }
3469
3470
2/2
✓ Branch 0 taken 10023 times.
✓ Branch 1 taken 6 times.
10029 if (scr->door[2]==dBOMB)
3471 {
3472 18 showbombeddoor(scr, dest, 2, offx, offy);
3473 6 }
3474
3475
2/2
✓ Branch 0 taken 9992 times.
✓ Branch 1 taken 37 times.
10029 if (scr->door[3]==dBOMB)
3476 {
3477 111 showbombeddoor(scr, dest, 3, offx, offy);
3478 37 }
3479 10029 }
3480
3481
3/4
✓ Branch 0 taken 18024 times.
✓ Branch 1 taken 2034 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18024 times.
20058 if (scr->stairx || scr->stairy)
3482 {
3483
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if (!hints)
3484 {
3485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if (!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3486 3369 putcombo(dest,scr->stairx+offx,scr->stairy+offy,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
3487 1123 }
3488 else
3489 {
3490
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(scr->flags&fWHISTLE)
3491 {
3492 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3493 48 int32_t tempitemx=-16+offx;
3494 48 int32_t tempitemy=-16+offy-playing_field_offset;
3495
3496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3497
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3498 {
3499 48 tempitemx=scr->stairx+offx;
3500 48 tempitemy=scr->stairy+offy;
3501 24 }
3502
3503 48 putitem2(dest, tempitemx, tempitemy, tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3504 48 }
3505 }
3506 2034 }
3507 20058 });
3508 }
3509 20058 }
3510
3511 9690 void draw_lens_over(BITMAP *dest)
3512 {
3513 9690 int w = 288;
3514 9690 int h = 240;
3515
3516
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9672 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
9690 static BITMAP *lens_scr = create_bitmap_ex(8,2*w,2*h);
3517 static int32_t last_width = -1;
3518 9690 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3519
3520 // Only redraw the circle if the size has changed
3521
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 20 times.
9690 if (width != last_width)
3522 {
3523 20 clear_to_color(lens_scr, BLACK);
3524 20 circlefill(lens_scr, w, h, width, 0);
3525 20 circle(lens_scr, w, h, width+2, 0);
3526 20 circle(lens_scr, w, h, width+5, 0);
3527 20 last_width=width;
3528 20 }
3529
3530 9690 masked_blit(lens_scr, dest, w-(HeroX()+8)+viewport.x, h-(HeroY()+8)+viewport.y, 0, playing_field_offset, 256, viewport.h);
3531 9690 do_primitives(dest, SPLAYER_LENS_OVER);
3532 9690 }
3533
3534 38494248 static void update_bmp_size(BITMAP** bmp_ptr, int w, int h)
3535 {
3536 38494248 BITMAP* bmp = *bmp_ptr;
3537
3/4
✓ Branch 0 taken 38494248 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38494242 times.
✓ Branch 3 taken 6 times.
38494248 if (bmp->w == w && bmp->h == h)
3538 38494242 return;
3539
3540 6 int depth = bitmap_color_depth(bmp);
3541 6 destroy_bitmap(bmp);
3542 6 *bmp_ptr = create_bitmap_ex(depth, w, h);
3543 38494248 }
3544
3545 32028 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3546 {
3547
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 32022 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
32028 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3548 32028 update_bmp_size(&wavebuf, 288, 240 - original_playing_field_offset);
3549
3550 32028 clear_to_color(wavebuf, BLACK);
3551 32028 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,framebuf->h-original_playing_field_offset);
3552
3553 int32_t ofs;
3554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32028 times.
32028 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3555
4/6
✓ Branch 0 taken 32028 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32028 times.
✓ Branch 4 taken 606 times.
✓ Branch 5 taken 31422 times.
32028 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3556 32028 int32_t amp2 = viewport.visible_height(show_bottom_8px);
3557
2/4
✓ Branch 0 taken 32028 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32028 times.
32028 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3558 32028 int32_t i=frame%amp2;
3559
3560
2/2
✓ Branch 0 taken 5382552 times.
✓ Branch 1 taken 32028 times.
5414580 for(int32_t j=0; j<viewport.visible_height(show_bottom_8px); j++)
3561 {
3562
3/4
✓ Branch 0 taken 2691276 times.
✓ Branch 1 taken 2691276 times.
✓ Branch 2 taken 2691276 times.
✗ Branch 3 not taken.
5382552 if(j&1 && interpol)
3563 {
3564 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3565 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3566 }
3567 else
3568 {
3569 5382552 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3570 }
3571
3572
1/2
✓ Branch 0 taken 5382552 times.
✗ Branch 1 not taken.
5382552 if(ofs)
3573 {
3574
2/2
✓ Branch 0 taken 1377933312 times.
✓ Branch 1 taken 5382552 times.
1383315864 for(int32_t k=0; k<256; k++)
3575 {
3576 1377933312 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3577 1377933312 }
3578 5382552 }
3579 5382552 }
3580 32028 }
3581
3582 28272 void draw_fuzzy(int32_t fuzz)
3583 // draws from right half of scrollbuf to framebuf
3584 {
3585 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3586 byte *start, *si, *di;
3587
3588
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28272 times.
28272 if(fuzz<1)
3589 fuzz = 1;
3590
3591 28272 xstep = 128%fuzz;
3592
3593
2/2
✓ Branch 0 taken 5890 times.
✓ Branch 1 taken 22382 times.
28272 if(xstep > 0)
3594 22382 xstep = fuzz-xstep;
3595
3596 28272 ystep = 112%fuzz;
3597
3598
2/2
✓ Branch 0 taken 8246 times.
✓ Branch 1 taken 20026 times.
28272 if(ystep > 0)
3599 20026 ystep = fuzz-ystep;
3600
3601 28272 firsty = 1;
3602
3603
2/2
✓ Branch 0 taken 28272 times.
✓ Branch 1 taken 1020148 times.
1048420 for(y=0; y<framebuf->h;)
3604 {
3605 1020148 start = &(scrollbuf_old->line[y][256]);
3606
3607
4/4
✓ Branch 0 taken 1006012 times.
✓ Branch 1 taken 6347064 times.
✓ Branch 2 taken 6332928 times.
✓ Branch 3 taken 1020148 times.
7353076 for(dy=0; dy<ystep && dy+y<framebuf->h; dy++)
3608 {
3609 6332928 si = start;
3610 6332928 di = &(framebuf->line[y+dy][0]);
3611 6332928 i = xstep;
3612 6332928 firstx = 1;
3613
3614
2/2
✓ Branch 0 taken 1621229568 times.
✓ Branch 1 taken 6332928 times.
1627562496 for(dx=0; dx<framebuf->w; dx++)
3615 {
3616 1621229568 *(di++) = *si;
3617
3618
2/2
✓ Branch 0 taken 1366065344 times.
✓ Branch 1 taken 255164224 times.
1621229568 if(++i >= fuzz)
3619 {
3620
2/2
✓ Branch 0 taken 248831296 times.
✓ Branch 1 taken 6332928 times.
255164224 if(!firstx)
3621 248831296 si += fuzz;
3622 else
3623 {
3624 6332928 si += fuzz-xstep;
3625 6332928 firstx = 0;
3626 }
3627
3628 255164224 i = 0;
3629 255164224 }
3630 1621229568 }
3631 6332928 }
3632
3633
2/2
✓ Branch 0 taken 991876 times.
✓ Branch 1 taken 28272 times.
1020148 if(!firsty)
3634 991876 y += fuzz;
3635 else
3636 {
3637 28272 y += ystep;
3638 28272 ystep = fuzz;
3639 28272 firsty = 0;
3640 }
3641 }
3642 28272 }
3643
3644 19231110 void updatescr(bool allowwavy)
3645 {
3646
4/6
✓ Branch 0 taken 323 times.
✓ Branch 1 taken 19230787 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 323 times.
✓ Branch 4 taken 323 times.
✗ Branch 5 not taken.
19231110 static BITMAP *wavybuf = create_bitmap_ex(8, framebuf->w, framebuf->h);
3647
4/6
✓ Branch 0 taken 323 times.
✓ Branch 1 taken 19230787 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 323 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 323 times.
19231110 static BITMAP *panorama = create_bitmap_ex(8, framebuf->w, framebuf->h);
3648 19231110 update_bmp_size(&wavybuf, framebuf->w, framebuf->h);
3649 19231110 update_bmp_size(&panorama, framebuf->w, framebuf->h);
3650
3651
2/2
✓ Branch 0 taken 19202969 times.
✓ Branch 1 taken 28141 times.
19231110 if(walk_through_walls)
3652 {
3653 28141 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3654 28141 }
3655
3656
1/2
✓ Branch 0 taken 19231110 times.
✗ Branch 1 not taken.
19231110 if(Showpal)
3657 dump_pal(framebuf);
3658
3659
2/2
✓ Branch 0 taken 18706947 times.
✓ Branch 1 taken 524163 times.
19231110 if(!Playing)
3660 524163 black_opening_count=0;
3661
3662
2/2
✓ Branch 0 taken 19053180 times.
✓ Branch 1 taken 177930 times.
19231110 if(black_opening_count<0) //shape is opening up
3663 {
3664 177930 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3665
3666
2/4
✓ Branch 0 taken 177930 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 177930 times.
177930 if(Advance||(!Paused))
3667 {
3668 177930 ++black_opening_count;
3669 177930 }
3670 177930 }
3671
2/2
✓ Branch 0 taken 19004340 times.
✓ Branch 1 taken 48840 times.
19053180 else if(black_opening_count>0) //shape is closing
3672 {
3673 48840 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3674
3675
2/4
✓ Branch 0 taken 48840 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48840 times.
48840 if(Advance||(!Paused))
3676 {
3677 48840 --black_opening_count;
3678 48840 }
3679 48840 }
3680
3681
3/4
✓ Branch 0 taken 19007774 times.
✓ Branch 1 taken 223336 times.
✓ Branch 2 taken 19007774 times.
✗ Branch 3 not taken.
19231110 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3682 {
3683 black_opening_shape = bosCIRCLE;
3684 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3685 refreshTints();
3686 refreshpal=true;
3687 }
3688
3689
2/2
✓ Branch 0 taken 18595651 times.
✓ Branch 1 taken 635459 times.
19231110 if(refreshpal)
3690 {
3691 635459 refreshpal=false;
3692 635459 RAMpal[253] = _RGB(0,0,0);
3693 635459 RAMpal[254] = _RGB(255,255,255);
3694 635459 hw_palette = &RAMpal;
3695 635459 update_hw_pal = true;
3696 635459 refresh_rgb_tables();
3697 635459 }
3698
3699 19231110 bool clearwavy = (wavy <= 0);
3700
3701
2/2
✓ Branch 0 taken 8572 times.
✓ Branch 1 taken 19222538 times.
19231110 if(wavy <= 0)
3702 {
3703 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3704 19222538 wavy = (DMaps[cur_dmap].flags&dmfWAVY ? 4 : 0);
3705 19222538 }
3706
3707 19231110 blit(framebuf, wavybuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3708
3709
6/6
✓ Branch 0 taken 32278 times.
✓ Branch 1 taken 19198832 times.
✓ Branch 2 taken 32156 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 32028 times.
19231110 if(wavy && Playing && allowwavy)
3710 {
3711 32028 draw_wavy(framebuf, wavybuf, wavy,false);
3712 32028 }
3713
3714
2/2
✓ Branch 0 taken 19222538 times.
✓ Branch 1 taken 8572 times.
19231110 if(clearwavy)
3715 19222538 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3716
2/4
✓ Branch 0 taken 8572 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8572 times.
8572 else if(Playing && !Paused)
3717 8572 wavy--; // Wavy was set by a script. Decrement it.
3718
3719
3/4
✓ Branch 0 taken 18706947 times.
✓ Branch 1 taken 524163 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18706947 times.
19231110 if(Playing && !Paused)
3720 18706947 ++light_wave_clk;
3721
3722
6/6
✓ Branch 0 taken 18706947 times.
✓ Branch 1 taken 524163 times.
✓ Branch 2 taken 277275 times.
✓ Branch 3 taken 18429672 times.
✓ Branch 4 taken 68 times.
✓ Branch 5 taken 277207 times.
19231110 if(Playing && msg_active && !screenscrolling)
3723 {
3724
2/2
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 277074 times.
277207 if(!(msg_bg_display_buf->clip))
3725 277074 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,176);
3726
2/2
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 277074 times.
277207 if(!(msg_portrait_display_buf->clip))
3727 277074 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,176);
3728
2/2
✓ Branch 0 taken 133 times.
✓ Branch 1 taken 277074 times.
277207 if(!(msg_txt_display_buf->clip))
3729 277074 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,176);
3730 277207 }
3731
3732
3/4
✓ Branch 0 taken 19231110 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19025043 times.
✓ Branch 3 taken 206067 times.
19231110 bool nosubscr = GameLoaded && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET);
3733
3734
2/2
✓ Branch 0 taken 19030316 times.
✓ Branch 1 taken 200794 times.
19231110 if(nosubscr)
3735 {
3736 200794 clear_to_color(panorama, 0);
3737 200794 blit(wavybuf,panorama,0,playing_field_offset,0,playing_field_offset/2,256,framebuf->h-playing_field_offset);
3738 200794 }
3739
3740 //TODO: Optimize blit 'overcalls' -Gleeok
3741
2/2
✓ Branch 0 taken 200794 times.
✓ Branch 1 taken 19030316 times.
19231110 BITMAP *source = nosubscr ? panorama : wavybuf;
3742 19231110 blit(source, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3743
3744 19231110 update_hw_screen();
3745 19231110 }
3746
3747 //----------------------------------------------------------------
3748
3749 static PALETTE syspal;
3750 int32_t onGUISnapshot()
3751 {
3752 char buf[200];
3753 int32_t num=0;
3754 do
3755 {
3756 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3757 }
3758 while(num<99999 && exists(buf));
3759
3760 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3761 InfoDialog("Error", "Failed to save snapshot").show();
3762
3763 return D_O_K;
3764 }
3765
3766 int32_t onNonGUISnapshot()
3767 {
3768 PALETTE temppal;
3769 get_palette(temppal);
3770 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3771
3772 char buf[200];
3773 int32_t num=0;
3774
3775 do
3776 {
3777 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3778 }
3779 while(num<99999 && exists(buf));
3780
3781 if (hero_scr && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET) && !key[KEY_ALT])
3782 {
3783 BITMAP *b = create_bitmap_ex(8, 256, viewport.visible_height(show_bottom_8px));
3784 clear_to_color(b,0);
3785 blit(framebuf,b,0,playing_field_offset/2,0,0,b->w,b->h);
3786 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3787 destroy_bitmap(b);
3788 }
3789 else
3790 {
3791 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3792 }
3793
3794 return D_O_K;
3795 }
3796
3797 int32_t onSnapshot()
3798 {
3799 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3800 {
3801 onGUISnapshot();
3802 }
3803 else
3804 {
3805 onNonGUISnapshot();
3806 }
3807
3808 return D_O_K;
3809 }
3810
3811 int32_t onSaveMapPic()
3812 {
3813 char buf[200];
3814 int32_t num=0;
3815 BITMAP* _screen_draw_buffer = NULL;
3816 _screen_draw_buffer = create_bitmap_ex(8,256,176);
3817
3818 do
3819 {
3820 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3821 }
3822 while(num<99999 && exists(buf));
3823
3824 BITMAP* mappic = create_bitmap_ex(8,(256*16),(176*8));
3825 clear_to_color(mappic, BLACK);
3826
3827 if(!mappic)
3828 {
3829 enter_sys_pal();
3830 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3831 exit_sys_pal();
3832 return D_O_K;;
3833 }
3834
3835 clear_to_color(_screen_draw_buffer, BLACK);
3836
3837 auto prev_viewport = viewport;
3838 viewport.x = 0;
3839 viewport.y = 0;
3840
3841 // draw the map
3842
3843 bool classic_draw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3844 for(int32_t y=0; y<8; y++)
3845 {
3846 for(int32_t x=0; x<16; x++)
3847 {
3848 if (!displayOnMap(x, y))
3849 continue;
3850
3851 int screen = map_scr_xy_to_index(x, y);
3852 auto scrs = loadscr2(screen);
3853 mapscr* scr = &scrs[0];
3854 if (!scr->is_valid())
3855 continue;
3856
3857 screen_handles_t screen_handles;
3858 for (int i = 0; i <= 6; i++)
3859 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
3860
3861 int xx = 0;
3862 int yy = -playing_field_offset;
3863
3864 if (!classic_draw)
3865 for (int layer = -7; layer <= -4; ++layer)
3866 do_ffc_layer(_screen_draw_buffer, layer, screen_handles[0], xx, yy);
3867
3868 if(classic_draw)
3869 {
3870 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3871 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3872 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3873 }
3874
3875 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3876 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3877 do_ffc_layer(_screen_draw_buffer, -3, screen_handles[0], xx, yy);
3878
3879 if(!classic_draw)
3880 {
3881 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3882 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3883 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3884 do_ffc_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3885 }
3886
3887 if(lenscheck(scr,0))
3888 putscr(scr, _screen_draw_buffer, 0, 0);
3889 do_ffc_layer(_screen_draw_buffer, 0, screen_handles[0], xx, yy);
3890 do_layer(_screen_draw_buffer, 0, screen_handles[1], xx, yy);
3891 do_ffc_layer(_screen_draw_buffer, 1, screen_handles[0], xx, yy);
3892
3893 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3894 {
3895 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3896 do_ffc_layer(_screen_draw_buffer, 2, screen_handles[0], xx, yy);
3897 }
3898
3899 putscrdoors(scr, _screen_draw_buffer, xx, yy);
3900 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3901 {
3902 do_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3903 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3904 {
3905 do_layer(_screen_draw_buffer, -2, screen_handles[1], xx, yy);
3906 do_layer(_screen_draw_buffer, -2, screen_handles[2], xx, yy);
3907 }
3908 }
3909
3910 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3911 {
3912 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3913 do_ffc_layer(_screen_draw_buffer, 3, screen_handles[0], xx, yy);
3914 }
3915
3916 do_layer(_screen_draw_buffer, 0, screen_handles[4], xx, yy);
3917 do_ffc_layer(_screen_draw_buffer, 4, screen_handles[0], xx, yy);
3918 do_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3919 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3920 {
3921 do_layer(_screen_draw_buffer, -1, screen_handles[1], xx, yy);
3922 do_layer(_screen_draw_buffer, -1, screen_handles[2], xx, yy);
3923 }
3924 do_layer(_screen_draw_buffer, 0, screen_handles[5], xx, yy);
3925 do_ffc_layer(_screen_draw_buffer, 5, screen_handles[0], xx, yy);
3926 if(replay_version_check(40))
3927 do_ffc_layer(_screen_draw_buffer, -1000, screen_handles[0], xx, yy);
3928 do_layer(_screen_draw_buffer, 0, screen_handles[6], xx, yy);
3929 do_ffc_layer(_screen_draw_buffer, 6, screen_handles[0], xx, yy);
3930 do_ffc_layer(_screen_draw_buffer, 7, screen_handles[0], xx, yy);
3931
3932 blit(_screen_draw_buffer, mappic, 0, 0, x*256, y*176, 256, 176);
3933 }
3934 }
3935
3936 viewport = prev_viewport;
3937 save_bitmap(buf,mappic,RAMpal);
3938 destroy_bitmap(mappic);
3939 destroy_bitmap(_screen_draw_buffer);
3940 return D_O_K;
3941 }
3942
3943 59 void f_Quit(int32_t type)
3944 {
3945
2/4
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59 times.
✗ Branch 3 not taken.
59 if(type==qQUIT && !Playing)
3946 return;
3947
3948 59 bool from_menu = is_sys_pal;
3949
3950
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if(!from_menu)
3951 {
3952 59 music_pause();
3953 59 pause_all_sfx();
3954 59 sys_mouse();
3955 59 }
3956 59 enter_sys_pal();
3957 59 clear_keybuf();
3958
3959
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 13 times.
59 if (replay_version_check(0, 10))
3960 13 replay_poll();
3961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if (replay_is_replaying())
3962 59 replay_peek_quit();
3963
3964
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
59 if (!replay_is_replaying())
3965 switch(type)
3966 {
3967 case qQUIT:
3968 onQuit();
3969 break;
3970
3971 case qRESET:
3972 onReset();
3973 break;
3974
3975 case qEXIT:
3976 onExit();
3977 break;
3978 }
3979
3980
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
59 if(Quit)
3981 {
3982 59 kill_sfx();
3983 59 music_stop();
3984 59 exit_sys_pal();
3985 59 update_hw_screen();
3986 59 }
3987 else
3988 {
3989 exit_sys_pal();
3990 if(!from_menu)
3991 {
3992 music_resume();
3993 resume_all_sfx();
3994 }
3995 }
3996
3997
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if(!from_menu)
3998 59 game_mouse();
3999 59 eat_buttons();
4000
4001 59 zc_readrawkey(KEY_ESC);
4002
4003 59 zc_readrawkey(KEY_ENTER);
4004 59 }
4005
4006 //----------------------------------------------------------------
4007
4008 int32_t onNoWalls()
4009 {
4010 cheats_enqueue(Cheat::Walls);
4011 return D_O_K;
4012 }
4013
4014 int32_t onIgnoreSideview()
4015 {
4016 cheats_enqueue(Cheat::IgnoreSideView);
4017 return D_O_K;
4018 }
4019
4020 19229703 int32_t input_idle(bool checkmouse)
4021 {
4022 static int32_t mx, my, mz, mb;
4023
4024
4/6
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5123906 times.
✓ Branch 3 taken 14105797 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5123906 times.
24353609 if(keypressed() || zc_key_pressed() ||
4025
4/8
✓ Branch 0 taken 5123906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5123906 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5123906 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5123906 times.
✗ Branch 7 not taken.
5123906 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4026 {
4027 14105797 idle_count = 0;
4028
4029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14105797 times.
14105797 if(active_count < MAX_ACTIVE)
4030 {
4031 14105797 ++active_count;
4032 14105797 }
4033 14105797 }
4034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5123906 times.
5123906 else if(idle_count < MAX_IDLE)
4035 {
4036 5123906 ++idle_count;
4037 5123906 active_count = 0;
4038 5123906 }
4039
4040 19229703 mx = mouse_x;
4041 19229703 my = mouse_y;
4042 19229703 mz = mouse_z;
4043 19229703 mb = mouse_b;
4044
4045 19229703 return idle_count;
4046 }
4047
4048 int32_t onGoFast()
4049 {
4050 cheats_enqueue(Cheat::Fast);
4051 return D_O_K;
4052 }
4053
4054 int32_t onKillCheat()
4055 {
4056 cheats_enqueue(Cheat::Kill);
4057 return D_O_K;
4058 }
4059
4060 int32_t onSecretsCheat()
4061 {
4062 cheats_enqueue(Cheat::TrigSecrets);
4063 return D_O_K;
4064 }
4065 int32_t onSecretsCheatPerm()
4066 {
4067 cheats_enqueue(Cheat::TrigSecretsPerm);
4068 return D_O_K;
4069 }
4070
4071 int32_t onShowLayer0()
4072 {
4073 show_layers[0] = !show_layers[0];
4074 return D_O_K;
4075 }
4076 int32_t onShowLayer1()
4077 {
4078 show_layers[1] = !show_layers[1];
4079 return D_O_K;
4080 }
4081 int32_t onShowLayer2()
4082 {
4083 show_layers[2] = !show_layers[2];
4084 return D_O_K;
4085 }
4086 int32_t onShowLayer3()
4087 {
4088 show_layers[3] = !show_layers[3];
4089 return D_O_K;
4090 }
4091 int32_t onShowLayer4()
4092 {
4093 show_layers[4] = !show_layers[4];
4094 return D_O_K;
4095 }
4096 int32_t onShowLayer5()
4097 {
4098 show_layers[5] = !show_layers[5];
4099 return D_O_K;
4100 }
4101 int32_t onShowLayer6()
4102 {
4103 show_layers[6] = !show_layers[6];
4104 return D_O_K;
4105 }
4106 int32_t onShowLayerO()
4107 {
4108 show_layer_over=!show_layer_over;
4109 return D_O_K;
4110 }
4111 int32_t onShowLayerP()
4112 {
4113 show_layer_push=!show_layer_push;
4114 return D_O_K;
4115 }
4116 int32_t onShowLayerS()
4117 {
4118 show_sprites=!show_sprites;
4119 return D_O_K;
4120 }
4121 int32_t onShowLayerF()
4122 {
4123 show_ffcs=!show_ffcs;
4124 return D_O_K;
4125 }
4126 int32_t onShowLayerW()
4127 {
4128 show_walkflags=!show_walkflags;
4129 if(show_walkflags)
4130 show_effectflags = false;
4131 return D_O_K;
4132 }
4133 int32_t onShowLayerE()
4134 {
4135 show_effectflags=!show_effectflags;
4136 if(show_effectflags)
4137 show_walkflags = false;
4138 return D_O_K;
4139 }
4140 int32_t onShowFFScripts()
4141 {
4142 show_ff_scripts=!show_ff_scripts;
4143 return D_O_K;
4144 }
4145 2 int32_t onShowHitboxes()
4146 {
4147 2 show_hitboxes=!show_hitboxes;
4148 2 return D_O_K;
4149 }
4150 int32_t onShowInfoOpacity()
4151 {
4152 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4153 zc_set_config("zc","debug_info_opacity",info_opacity);
4154 return D_O_K;
4155 }
4156
4157 int32_t onLightSwitch()
4158 {
4159 cheats_enqueue(Cheat::Light);
4160 return D_O_K;
4161 }
4162
4163 int32_t onGoTo();
4164 int32_t onGoToComplete();
4165
4166 19229703 bool handle_close_btn_quit()
4167 {
4168
1/2
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
19229703 if(close_button_quit)
4169 {
4170 close_button_quit=false;
4171 f_Quit(qEXIT);
4172 }
4173 19229703 return (exiting_program = Quit==qEXIT);
4174 }
4175
4176 19229703 void syskeys()
4177 {
4178 19229703 update_system_keys();
4179
4180 int32_t oldtitle_version;
4181
4182 19229703 poll_joystick();
4183
4184 19229703 handle_close_btn_quit();
4185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19229703 times.
19229703 if(Quit == qEXIT) return;
4186
4187
2/10
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19229703 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
19229703 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4188 {
4189 System();
4190 }
4191
4192 19229703 mouse_down=gui_mouse_b();
4193
4194
1/2
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
19229703 if(zc_read_system_key(KEY_F1))
4195 {
4196 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4197 {
4198 halt=!halt;
4199 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4200 }
4201 else
4202 {
4203 Throttlefps=!Throttlefps;
4204 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4205 }
4206 }
4207
4208
1/2
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
19229703 if(zc_read_system_key(KEY_F2))
4209 {
4210 ShowFPS=!ShowFPS;
4211 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4212 }
4213
4214
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 19229703 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
19229703 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4215
4216
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 19229703 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
19229703 if(zc_read_system_key(KEY_F4) && Playing)
4217 {
4218 Paused=true;
4219 Advance=true;
4220 }
4221
4222
1/2
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
19229703 if(zc_read_system_key(KEY_F6)) onTryQuit();
4223
4224 #ifndef ALLEGRO_MACOSX
4225
1/2
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
19229703 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4226
4227
1/2
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
19229703 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4228 #else
4229 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4230
4231 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4232 #endif
4233
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 19229703 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
19229703 if(zc_read_system_key(KEY_F5)&&(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)) onSaveMapPic();
4234
4235
1/2
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
19229703 if (zc_read_system_key(KEY_F12))
4236 {
4237 onSnapshot();
4238 }
4239
4240
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 19229703 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
19229703 if(debug_enabled && zc_read_system_key(KEY_TAB))
4241 set_debug(!get_debug());
4242
4243
1/2
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
19229703 if(CheatModifierKeys())
4244 {
4245 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4246 {
4247 if(!bindable_cheat(c))
4248 continue;
4249 if(get_debug() || cheat >= cheat_lvl(c))
4250 {
4251 if(checkcheat(c))
4252 cheats_hit_bind(c);
4253 }
4254 }
4255 }
4256
4257
1/2
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
19229703 if(volkeys)
4258 {
4259 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4260
4261 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4262
4263 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4264
4265 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4266 }
4267
4268
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 19229703 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
19229703 if(!get_debug() || !SystemKeys || replay_is_replaying())
4269 19229703 goto bottom;
4270
4271 if(zc_readkey(KEY_P)) Paused=!Paused;
4272
4273 if(zc_readkey(KEY_A))
4274 {
4275 Paused=true;
4276 Advance=true;
4277 }
4278
4279 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4280 #ifndef ALLEGRO_MACOSX
4281 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4282
4283 if(zc_readkey(KEY_F7))
4284 {
4285 Matrix(ss_speed, ss_density, 0);
4286 game_pal();
4287 }
4288 #else
4289 // The reason these are different on Mac in the first place is that
4290 // the OS doesn't let us use F9 and F10...
4291 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4292
4293 if(zc_readkey(KEY_F9))
4294 {
4295 Matrix(ss_speed, ss_density, 0);
4296 game_pal();
4297 }
4298 #endif
4299 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4300 {
4301 //change containers
4302 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4303 {
4304 //magic containers
4305 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4306 {
4307 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4308 }
4309 else
4310 {
4311 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4312 }
4313 }
4314 else
4315 {
4316 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4317 {
4318 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4319 }
4320 else
4321 {
4322 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4323 }
4324 }
4325 }
4326
4327 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4328 {
4329 //change containers
4330 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4331 {
4332 //magic containers
4333 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4334 {
4335 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4336 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4337 //heart containers
4338 }
4339 else
4340 {
4341 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4342 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4343 }
4344 }
4345 else
4346 {
4347 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4348 {
4349 game->set_magic(zc_max(game->get_magic()-1,0));
4350 }
4351 else
4352 {
4353 game->set_life(zc_max(game->get_life()-1,0));
4354 }
4355 }
4356 }
4357
4358 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4359
4360 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4361
4362 verifyBothWeapons();
4363
4364 bottom:
4365
4366
1/2
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
19229703 if(input_idle(true) > after_time())
4367 {
4368 Matrix(ss_speed, ss_density, 0);
4369 game_pal();
4370 }
4371 19229703 }
4372
4373 1531652 void checkQuitKeys()
4374 {
4375 #ifndef ALLEGRO_MACOSX
4376
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1531652 times.
1531652 if(key[KEY_F9]) f_Quit(qRESET);
4377
4378
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1531652 times.
1531652 if(key[KEY_F10]) f_Quit(qEXIT);
4379 #else
4380 if(key[KEY_F7]) f_Quit(qRESET);
4381
4382 if(key[KEY_F8]) f_Quit(qEXIT);
4383 #endif
4384 1531652 }
4385
4386 19229903 bool CheatModifierKeys()
4387 {
4388 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4389 // to trigger cheats.
4390
2/2
✓ Branch 0 taken 19229603 times.
✓ Branch 1 taken 300 times.
19229903 if (replay_is_replaying())
4391 19229603 return false;
4392
4393
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4394
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4395
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4396 {
4397
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4398 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4399 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4400 {
4401 return true;
4402 }
4403 }
4404 100 return false;
4405 19229703 }
4406
4407 //99:05:54, for some reason?
4408 #define OLDMAXTIME 21405240
4409 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4410 #define MAXTIME 1944000000
4411
4412 // (qr, value)
4413 427 static std::queue<std::pair<int, bool>> change_qr_queue;
4414
4415 7 void enqueue_qr_change(int qr, bool value)
4416 {
4417 7 change_qr_queue.push({qr, value});
4418 7 }
4419
4420 // During regular play, QR changes issued through `syskey` / `System` and enqueued
4421 // and soon executed here.
4422 // During playing back a replay file, the replay system adds to the same queue and
4423 // is executed here too.
4424 // This is currently only used to allow users to configure qr_HIDE_BOTTOM_8_PIXELS, but
4425 // could be later extended to all QRs (perhaps as a cheat).
4426 19230138 void process_enqueued_qr_changes()
4427 {
4428
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 19230037 times.
19230138 if (replay_is_replaying())
4429 19230037 replay_do_qrs();
4430
4431
2/2
✓ Branch 0 taken 19230138 times.
✓ Branch 1 taken 7 times.
19230145 while (!change_qr_queue.empty())
4432 {
4433 28 auto [qr, value] = change_qr_queue.front();
4434 7 change_qr_queue.pop();
4435
4436 // Don't modify `quest_rules`, as that is used to store the canonical QR value which can be reset to
4437 // via system menus. Changing the unpacked array is enough to modify the engine's behavior.
4438 14 _qrs_unpacked[qr] = value;
4439 7 apply_qr_rule(qr);
4440
4441
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if (replay_is_recording())
4442 2 replay_step_qr(qr, value);
4443 }
4444 19230138 }
4445
4446 19231110 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4447 {
4448
1/2
✓ Branch 0 taken 19231110 times.
✗ Branch 1 not taken.
19231110 if(zcmusic!=NULL)
4449 {
4450 zcmusic_poll();
4451 }
4452 19231110 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4453
4454 19231110 updatescr(allowwavy);
4455
4456 19231110 Advance=false;
4457
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 19231110 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 19231110 times.
19231110 while(Paused && !Advance && !Quit)
4458 {
4459 // have to call this, otherwise we'll get an infinite loop
4460 syskeys();
4461 if(allowF6Script)
4462 {
4463 FFCore.runF6Engine();
4464 }
4465
4466 #ifdef _WIN32
4467
4468 if(use_dwm_flush)
4469 {
4470 do_DwmFlush();
4471 }
4472
4473 #endif
4474
4475 // to keep music playing
4476 if(zcmusic!=NULL)
4477 {
4478 zcmusic_poll();
4479 }
4480
4481 update_hw_screen();
4482 }
4483
4484
2/2
✓ Branch 0 taken 19229733 times.
✓ Branch 1 taken 1377 times.
19231110 if(Quit)
4485 1377 return;
4486
4487
3/4
✓ Branch 0 taken 18705897 times.
✓ Branch 1 taken 523836 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18705897 times.
19229733 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4488 18705897 game->change_time(1);
4489
4490 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4491
4492 19229733 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4493
2/2
✓ Branch 0 taken 9430121 times.
✓ Branch 1 taken 9799612 times.
19229733 if (replay_version_check(0, 16))
4494 9799612 should_reset_down_state = replay_version_check(11, 16);
4495
2/2
✓ Branch 0 taken 15096705 times.
✓ Branch 1 taken 4133028 times.
19229733 if (should_reset_down_state)
4496 {
4497
2/2
✓ Branch 0 taken 74394504 times.
✓ Branch 1 taken 4133028 times.
78527532 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4498 74394504 down_control_states[i] = raw_control_state[i];
4499 4133028 }
4500
4501
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 19229703 times.
19229733 if (replay_is_active())
4502 {
4503
2/2
✓ Branch 0 taken 1545427 times.
✓ Branch 1 taken 17684276 times.
19229703 if (replay_version_check(3))
4504 17684276 replay_poll();
4505
4506
4/4
✓ Branch 0 taken 7478911 times.
✓ Branch 1 taken 11750792 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7378376 times.
19229703 if (replay_version_check(11) || replay_version_check(6, 8))
4507 11851327 replay_peek_input();
4508 19229703 }
4509
4510 19229733 process_enqueued_qr_changes();
4511
4512 19229733 load_control_called_this_frame = false;
4513
4514 19229733 poll_keyboard();
4515 19229733 update_keys();
4516
4517 19229733 ++frame;
4518
4519
2/2
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 19229603 times.
19229733 if (replay_is_replaying())
4520 19229603 replay_do_cheats();
4521 19229733 syskeys();
4522
4523 // The mouse variables can change from the mouse thread at anytime during a frame,
4524 // so save the result at the start so that replaying is consistent.
4525 19229733 script_mouse_x = gui_mouse_x();
4526 19229733 script_mouse_y = gui_mouse_y();
4527 19229733 script_mouse_z = mouse_z;
4528 19229733 script_mouse_b = mouse_b;
4529
4530 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4531 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4532 // approach here means it doesn't matter which call adds the cheat.
4533 19229733 cheats_execute_queued();
4534
4535
2/2
✓ Branch 0 taken 130 times.
✓ Branch 1 taken 19229603 times.
19229733 if (replay_is_replaying())
4536 19229603 replay_peek_quit();
4537
2/2
✓ Branch 0 taken 19229662 times.
✓ Branch 1 taken 71 times.
19229733 if (GameFlags & GAMEFLAG_TRYQUIT)
4538 71 replay_step_quit(0);
4539
2/2
✓ Branch 0 taken 3327 times.
✓ Branch 1 taken 19226406 times.
19229733 if(allowF6Script)
4540 19226406 FFCore.runF6Engine();
4541
2/2
✓ Branch 0 taken 770 times.
✓ Branch 1 taken 19228963 times.
19229733 if (Quit)
4542 770 replay_step_quit(Quit);
4543
4544 #ifdef _WIN32
4545
4546 if(use_dwm_flush)
4547 {
4548 do_DwmFlush();
4549 }
4550
4551 #endif
4552
4553
2/2
✓ Branch 0 taken 219006 times.
✓ Branch 1 taken 19010727 times.
19229733 if(sfxcleanup)
4554 19010727 sfx_cleanup();
4555
4556 19229733 frame_timings_poll();
4557
4558 #ifdef __EMSCRIPTEN__
4559 // Yield the main thread back to the browser occasionally.
4560 if (is_headless())
4561 {
4562 static int rate = 10000;
4563 static int force_yield = rate;
4564 if (force_yield++ >= rate)
4565 {
4566 force_yield = 0;
4567 emscripten_sleep(0);
4568 }
4569 }
4570 #endif
4571
4572
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 19229633 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
19229733 if (zqtesting_mode && test_mode_auto_restart)
4573 {
4574 static auto last_write_time = fs::last_write_time(qstpath);
4575 static auto last_check = std::chrono::system_clock::now();
4576
4577 if (std::chrono::system_clock::now() - last_check > 200ms)
4578 {
4579 last_check = std::chrono::system_clock::now();
4580 auto write_time = fs::last_write_time(qstpath);
4581 if (last_write_time != write_time)
4582 {
4583 last_write_time = write_time;
4584 disableClickToFreeze = false;
4585 Quit = qRESET;
4586 replay_quit();
4587 }
4588 }
4589 }
4590 19231110 }
4591
4592 590 void zapout()
4593 {
4594 590 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4595 590 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4596
4597 590 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4598 590 script_drawing_commands.Clear();
4599
4600 // zap out
4601
2/2
✓ Branch 0 taken 590 times.
✓ Branch 1 taken 14160 times.
14750 for(int32_t i=1; i<=24; i++)
4602 {
4603 14160 draw_fuzzy(i);
4604 14160 advanceframe(true);
4605
4606
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14160 times.
14160 if(Quit)
4607 {
4608 break;
4609 }
4610 14160 }
4611 590 }
4612
4613 588 void zapin()
4614 {
4615 588 FFCore.warpScriptCheck();
4616 588 draw_screen();
4617 588 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4618 588 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4619
4620 // zap out
4621 588 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4622
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 14112 times.
14700 for(int32_t i=24; i>=1; i--)
4623 {
4624 14112 draw_fuzzy(i);
4625 14112 advanceframe(true);
4626
4627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14112 times.
14112 if(Quit)
4628 {
4629 break;
4630 }
4631 14112 }
4632 588 }
4633
4634
4635 239 void wavyout(bool showhero)
4636 {
4637 239 draw_screen(showhero);
4638
4639 239 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4640 239 clear_to_color(wavebuf,0);
4641 239 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4642
4643 static PALETTE wavepal;
4644
4645 int32_t ofs;
4646 239 int32_t amplitude=8;
4647
4648 239 int32_t wavelength=4;
4649 239 int height = viewport.visible_height(show_bottom_8px);
4650 239 double palpos=0, palstep=4, palstop=126;
4651
4652 239 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4653
2/2
✓ Branch 0 taken 238 times.
✓ Branch 1 taken 10021 times.
10259 for(int32_t i=0; i<height; i+=wavelength)
4654 {
4655
2/2
✓ Branch 0 taken 2565376 times.
✓ Branch 1 taken 10021 times.
2575397 for(int32_t l=0; l<256; l++)
4656 {
4657 2565376 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4658 2565376 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4659 2565376 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4660 2565376 }
4661
4662 10021 palpos+=palstep;
4663
4664
1/2
✓ Branch 0 taken 10021 times.
✗ Branch 1 not taken.
10021 if(palpos>=0)
4665 {
4666 10021 hw_palette = &wavepal;
4667 10021 update_hw_pal = true;
4668 10021 }
4669 else
4670 {
4671 hw_palette = &RAMpal;
4672 update_hw_pal = true;
4673 }
4674
4675
2/2
✓ Branch 0 taken 1684936 times.
✓ Branch 1 taken 10021 times.
1694957 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4676 {
4677
2/2
✓ Branch 0 taken 431343616 times.
✓ Branch 1 taken 1684936 times.
433028552 for(int32_t k=0; k<256; k++)
4678 {
4679 431343616 ofs=0;
4680
4681
4/4
✓ Branch 0 taken 210323456 times.
✓ Branch 1 taken 221020160 times.
✓ Branch 2 taken 105161728 times.
✓ Branch 3 taken 105161728 times.
431343616 if((j<i)&&(j&1))
4682 {
4683 105161728 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4684 105161728 }
4685
4686 431343616 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4687 431343616 }
4688 1684936 }
4689
4690 10021 advanceframe(true);
4691
4692
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10020 times.
10021 if(Quit)
4693 1 break;
4694 10020 }
4695
4696 239 destroy_bitmap(wavebuf);
4697
4698 239 hw_palette = &RAMpal;
4699 239 update_hw_pal = true;
4700 239 }
4701
4702 236 void wavyin()
4703 {
4704 236 draw_screen();
4705
4706 236 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4707 236 clear_to_color(wavebuf,0);
4708 236 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4709
4710 static PALETTE wavepal;
4711
4712 236 refreshpal=false;
4713 int32_t ofs;
4714 236 int32_t amplitude=8;
4715 236 int32_t wavelength=4;
4716 236 int height = viewport.visible_height(show_bottom_8px);
4717 236 double palpos=height, palstep=4, palstop=126;
4718
4719 236 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4720
2/2
✓ Branch 0 taken 235 times.
✓ Branch 1 taken 9879 times.
10114 for(int32_t i=0; i<height; i+=wavelength)
4721 {
4722
2/2
✓ Branch 0 taken 2529024 times.
✓ Branch 1 taken 9879 times.
2538903 for(int32_t l=0; l<256; l++)
4723 {
4724 2529024 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4725 2529024 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4726 2529024 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4727 2529024 }
4728
4729 9879 palpos-=palstep;
4730
4731
1/2
✓ Branch 0 taken 9879 times.
✗ Branch 1 not taken.
9879 if(palpos>=0)
4732 {
4733 9879 hw_palette = &wavepal;
4734 9879 update_hw_pal = true;
4735 9879 }
4736 else
4737 {
4738 hw_palette = &RAMpal;
4739 update_hw_pal = true;
4740 }
4741
4742
2/2
✓ Branch 0 taken 1661080 times.
✓ Branch 1 taken 9879 times.
1670959 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4743 {
4744
2/2
✓ Branch 0 taken 425236480 times.
✓ Branch 1 taken 1661080 times.
426897560 for(int32_t k=0; k<256; k++)
4745 {
4746 425236480 ofs=0;
4747
4748
4/4
✓ Branch 0 taken 215168256 times.
✓ Branch 1 taken 210068224 times.
✓ Branch 2 taken 108848640 times.
✓ Branch 3 taken 106319616 times.
425236480 if((j<(height-1-i))&&(j&1))
4749 {
4750 106319616 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4751 106319616 }
4752
4753 425236480 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4754 425236480 }
4755 1661080 }
4756
4757 9879 advanceframe(true);
4758
4759
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9878 times.
9879 if(Quit)
4760 1 break;
4761 9878 }
4762
4763 236 destroy_bitmap(wavebuf);
4764
4765 236 hw_palette = &RAMpal;
4766 236 update_hw_pal = true;
4767 236 }
4768
4769 4608 void blackscr(int32_t fcnt,bool showsubscr)
4770 {
4771 4608 reset_pal_cycling();
4772 4608 script_drawing_commands.Clear();
4773
4774 4608 FFCore.warpScriptCheck();
4775 4608 bool showtime = game->should_show_time();
4776
2/2
✓ Branch 0 taken 4601 times.
✓ Branch 1 taken 137797 times.
142398 while(fcnt>0)
4777 {
4778 137797 clear_bitmap(framebuf);
4779
4780
2/2
✓ Branch 0 taken 59340 times.
✓ Branch 1 taken 78457 times.
137797 if(showsubscr)
4781 {
4782 78457 put_passive_subscr(framebuf,0,0,showtime,sspUP);
4783
4/4
✓ Branch 0 taken 70627 times.
✓ Branch 1 taken 7830 times.
✓ Branch 2 taken 1410 times.
✓ Branch 3 taken 69217 times.
78457 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4784 {
4785 9240 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
4786 9240 }
4787 78457 }
4788
4789 137797 advanceframe(true);
4790
4791
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 137790 times.
137797 if(Quit)
4792 7 break;
4793
4794 137790 --fcnt;
4795 }
4796 4608 }
4797
4798 2877 void openscreen(int32_t shape)
4799 {
4800 2877 update_viewport();
4801 2877 is_opening_screen = true;
4802 2877 reset_pal_cycling();
4803 2877 black_opening_count=0;
4804
4805
3/4
✓ Branch 0 taken 531 times.
✓ Branch 1 taken 2346 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 531 times.
2877 if(COOLSCROLL || shape>-1)
4806 {
4807 2346 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4808 2346 return;
4809 }
4810 else
4811 {
4812 531 Hero.setDontDraw(true);
4813 531 show_subscreen_dmap_dots=false;
4814 531 show_subscreen_numbers=false;
4815 531 show_subscreen_life=false;
4816 }
4817
4818 531 int32_t x=128;
4819
4820 531 FFCore.warpScriptCheck();
4821
2/2
✓ Branch 0 taken 531 times.
✓ Branch 1 taken 42480 times.
43011 for(int32_t i=0; i<80; i++)
4822 {
4823 42480 draw_screen();
4824 42480 x=128-(((i*128/80)/8)*8);
4825
4826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42480 times.
42480 if(x>0)
4827 {
4828 42480 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4829 42480 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4830 42480 }
4831
4832 42480 advanceframe(true);
4833
4834
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42480 times.
42480 if(Quit)
4835 {
4836 break;
4837 }
4838 42480 }
4839
4840 531 Hero.setDontDraw(false);
4841 531 show_subscreen_items=true;
4842 531 show_subscreen_dmap_dots=true;
4843 531 show_subscreen_numbers=true;
4844 531 show_subscreen_life=true;
4845 2877 }
4846
4847 15 void closescreen(int32_t shape)
4848 {
4849 15 is_opening_screen = false;
4850 15 reset_pal_cycling();
4851 15 black_opening_count=0;
4852
4853
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15 if(COOLSCROLL || shape>-1)
4854 {
4855 15 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4856 15 return;
4857 }
4858 else
4859 {
4860 Hero.setDontDraw(true);
4861 show_subscreen_dmap_dots=false;
4862 show_subscreen_numbers=false;
4863 // show_subscreen_items=false;
4864 show_subscreen_life=false;
4865 }
4866
4867 int32_t x=128;
4868
4869 FFCore.warpScriptCheck();
4870 for(int32_t i=79; i>=0; --i)
4871 {
4872 draw_screen();
4873 x=128-(((i*128/80)/8)*8);
4874
4875 if(x>0)
4876 {
4877 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4878 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4879 }
4880
4881 advanceframe(true);
4882
4883 if(Quit)
4884 {
4885 break;
4886 }
4887 }
4888
4889 Hero.setDontDraw(false);
4890 show_subscreen_items=true;
4891 show_subscreen_dmap_dots=true;
4892 15 }
4893
4894 326 int32_t TriforceCount()
4895 {
4896 326 int32_t c=0;
4897
4898
2/2
✓ Branch 0 taken 2608 times.
✓ Branch 1 taken 326 times.
2934 for(int32_t i=1; i<=8; i++)
4899
2/2
✓ Branch 0 taken 496 times.
✓ Branch 1 taken 2112 times.
4720 if(game->lvlitems[i]&(1 << li_mcguffin))
4900 2112 ++c;
4901
4902 326 return c;
4903 }
4904
4905 int32_t onCustomGame()
4906 {
4907 auto save = get_unset_save_slot();
4908 if (!save)
4909 return D_CLOSE;
4910
4911 if (prompt_for_quest_path(save->header->qstpath))
4912 {
4913 save->header->qstpath = qstpath;
4914 return D_O_K;
4915 }
4916
4917 return D_CLOSE;
4918 }
4919
4920 int32_t onContinue()
4921 {
4922 return D_CLOSE;
4923 }
4924
4925 int32_t onThrottleFPS()
4926 {
4927 Throttlefps = !Throttlefps;
4928 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4929 return D_O_K;
4930 }
4931
4932 int32_t onWinPosSave()
4933 {
4934 SaveWinPos = !SaveWinPos;
4935 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4936 return D_O_K;
4937 }
4938 int32_t onIntegerScaling()
4939 {
4940 scaleForceInteger = !scaleForceInteger;
4941 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4942 return D_O_K;
4943 }
4944 int32_t onStretchGame()
4945 {
4946 stretchGame = !stretchGame;
4947 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4948 return D_O_K;
4949 }
4950
4951 int32_t onClickToFreeze()
4952 {
4953 ClickToFreeze = !ClickToFreeze;
4954 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4955 return D_O_K;
4956 }
4957
4958 int32_t OnSaveZCConfig()
4959 {
4960 if(jwin_alert3(
4961 "Save Configuration",
4962 "Are you sure that you wish to save your present configuration settings?",
4963 "This will overwrite your prior settings!",
4964 NULL,
4965 "&Yes",
4966 "&No",
4967 NULL,
4968 'y',
4969 'n',
4970 0,
4971 get_zc_font(font_lfont)) == 1)
4972 {
4973 save_game_configs();
4974 return D_O_K;
4975 }
4976 else return D_O_K;
4977 }
4978
4979 int32_t OnnClearQuestDir()
4980 {
4981 auto current_path = fs::current_path() / "quests";
4982 if(jwin_alert3(
4983 "Clear Current Directory Cache",
4984 "Are you sure that you wish to reset where ZC Player looks for quests?",
4985 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4986 NULL,
4987 "&Yes",
4988 "&No",
4989 NULL,
4990 'y',
4991 'n',
4992 0,
4993 get_zc_font(font_lfont)) == 1)
4994 {
4995 zc_set_config("zeldadx","quest_dir","quests");
4996 flush_config_file();
4997 strcpy(qstdir,"quests");
4998 #ifdef __EMSCRIPTEN__
4999 em_sync_fs();
5000 #endif
5001 return D_O_K;
5002 }
5003 else return D_O_K;
5004 }
5005
5006 int32_t onConsole()
5007 {
5008 if ( !console_enabled )
5009 {
5010 AlertDialog("ZC Console",
5011 "Open the ZC Console?"
5012 "\nThis will display any messages logged by scripts,"
5013 " including errors.",
5014 [&](bool ret,bool)
5015 {
5016 if(ret)
5017 {
5018 FFCore.ZScriptConsole(true);
5019 }
5020 }).show();
5021 return D_O_K;
5022 }
5023 else
5024 {
5025 FFCore.ZScriptConsole(false);
5026 return D_O_K;
5027 }
5028 }
5029
5030 int32_t onClrConsoleOnReload()
5031 {
5032 clearConsoleOnReload = !clearConsoleOnReload;
5033 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5034 return D_O_K;
5035 }
5036 int32_t onClrConsoleOnLoad()
5037 {
5038 clearConsoleOnLoad = !clearConsoleOnLoad;
5039 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5040 return D_O_K;
5041 }
5042
5043
5044 int32_t onFrameSkip()
5045 {
5046 FrameSkip = !FrameSkip;
5047 return D_O_K;
5048 }
5049
5050 int32_t onSaveDragResize()
5051 {
5052 SaveDragResize = !SaveDragResize;
5053 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5054 return D_O_K;
5055 }
5056
5057 int32_t onDragAspect()
5058 {
5059 DragAspect = !DragAspect;
5060 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5061 return D_O_K;
5062 }
5063
5064 int32_t onTransLayers()
5065 {
5066 TransLayers = !TransLayers;
5067 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5068 return D_O_K;
5069 }
5070
5071 int32_t onNESquit()
5072 {
5073 NESquit = !NESquit;
5074 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5075 return D_O_K;
5076 }
5077
5078 int32_t onVolKeys()
5079 {
5080 volkeys = !volkeys;
5081 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5082 return D_O_K;
5083 }
5084
5085 int32_t onShowFPS()
5086 {
5087 ShowFPS = !ShowFPS;
5088 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5089 return D_O_K;
5090 }
5091
5092 int32_t onShowTime()
5093 {
5094 ShowGameTime = !ShowGameTime;
5095 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5096 return D_O_K;
5097 }
5098
5099 2269104954 bool is_Fkey(int32_t k)
5100 {
5101
2/2
✓ Branch 0 taken 230756436 times.
✓ Branch 1 taken 2038348518 times.
2269104954 switch(k)
5102 {
5103 case KEY_F1:
5104 case KEY_F2:
5105 case KEY_F3:
5106 case KEY_F4:
5107 case KEY_F5:
5108 case KEY_F6:
5109 case KEY_F7:
5110 case KEY_F8:
5111 case KEY_F9:
5112 case KEY_F10:
5113 case KEY_F11:
5114 case KEY_F12:
5115 230756436 return true;
5116 }
5117
5118 2038348518 return false;
5119 2269104954 }
5120
5121 void kb_getkey(DIALOG *d);
5122
5123 //Used by all keyboard key settings dialogues.
5124 void kb_clearjoystick(DIALOG *d)
5125 {
5126 d->flags|=D_SELECTED;
5127
5128 jwin_button_proc(MSG_DRAW,d,0);
5129 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5130 // text_mode(vc(11));
5131 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5132 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5133
5134 update_hw_screen();
5135
5136 clear_keybuf();
5137 int32_t k = next_press_key();
5138 clear_keybuf();
5139
5140 //shnarf
5141 //47=f1
5142 //59=esc
5143 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5144 // *((int32_t*)d->dp3) = k;
5145 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5146
5147
5148 d->flags&=~D_SELECTED;
5149 }
5150
5151 //Clears key to 0.
5152 //Used by all keyboard key settings dialogues.
5153 void kb_clearkey(DIALOG *d);
5154
5155 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5156 {
5157 switch(msg)
5158 {
5159 case MSG_KEY:
5160 case MSG_CLICK:
5161
5162 kb_clearjoystick(d);
5163
5164 while(gui_mouse_b())
5165 {
5166 clear_keybuf();
5167 rest(1);
5168 }
5169
5170 return D_REDRAW;
5171 }
5172
5173 return jwin_button_proc(msg,d,c);
5174 }
5175
5176 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5177 //Only used in keyboard settings dialogues to clear keys.
5178 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5179
5180 int32_t j_getbtn(DIALOG *d)
5181 {
5182 d->flags|=D_SELECTED;
5183 jwin_button_proc(MSG_DRAW,d,0);
5184 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5185 // text_mode(vc(11));
5186 int32_t y = screen->h/2 - 12;
5187 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5188 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5189 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5190
5191 update_hw_screen();
5192
5193 int32_t b = next_joy_input(true);
5194 if (b == -2)
5195 return D_CLOSE;
5196
5197 if(b>=0)
5198 *((int32_t*)d->dp3) = b;
5199
5200 d->flags&=~D_SELECTED;
5201
5202 return D_O_K;
5203 }
5204
5205 void j_getstick(DIALOG *d)
5206 {
5207 d->flags|=D_SELECTED;
5208 jwin_button_proc(MSG_DRAW,d,0);
5209 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5210 // text_mode(vc(11));
5211 int32_t y = screen->h/2 - 12;
5212 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5213 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5214 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5215
5216 update_hw_screen();
5217
5218 int32_t b = next_joy_input(false);
5219
5220 if(b>=0)
5221 *((int32_t*)d->dp3) = b;
5222
5223 d->flags&=~D_SELECTED;
5224 }
5225
5226 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5227 {
5228 switch(msg)
5229 {
5230 case MSG_KEY:
5231 case MSG_CLICK:
5232
5233 int ret = j_getbtn(d);
5234 if (ret != D_O_K)
5235 return ret;
5236
5237 while(gui_mouse_b()) {
5238 rest(1);
5239 clear_keybuf();
5240 }
5241
5242 return D_REDRAW;
5243 }
5244
5245 return jwin_button_proc(msg,d,c);
5246 }
5247
5248 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5249 {
5250 switch(msg)
5251 {
5252 case MSG_KEY:
5253 case MSG_CLICK:
5254
5255 j_getstick(d);
5256
5257 while(gui_mouse_b()) {
5258 rest(1);
5259 clear_keybuf();
5260 }
5261
5262 return D_REDRAW;
5263 }
5264
5265 return jwin_button_proc(msg,d,c);
5266 }
5267
5268 //shnarf
5269 extern const char *key_str[];
5270 std::string get_keystr(int key);
5271
5272 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5273
5274 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5275 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5276 str_primary_stick[80], str_secondary_stick[80];
5277
5278 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5279 {
5280 //these are here to bypass compiler warnings about unused arguments
5281 c=c;
5282
5283 if (d->w == 1)
5284 {
5285 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5286 {
5287 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5288 return D_CLOSE;
5289 }
5290 }
5291
5292 if(msg==MSG_DRAW)
5293 {
5294 switch(d->w)
5295 {
5296 case 0:
5297 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5298 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5299 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5300 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5301 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5302 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5303 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5304 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5305 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5306 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5307 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5308 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5309 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5310 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5311 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5312 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5313 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5314 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5315 break;
5316
5317 case 1:
5318 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5319 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5320 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5321 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5322 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5323 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5324 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5325 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5326 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5327 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5328 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5329 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5330 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5331 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5332 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5333 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5334 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5335 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5336 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5337 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5338 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5339 break;
5340
5341 case 2:
5342 sprintf(str_a," %3d",midi_volume);
5343 sprintf(str_l," %3d",emusic_volume);
5344 sprintf(str_r," %3d",sfx_volume);
5345 strcpy(str_s,pan_str[pan_style]);
5346 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5347 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5348 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5349 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5350 break;
5351 }
5352 }
5353
5354 return D_O_K;
5355 }
5356
5357 int32_t set_vol(void *dp3, int32_t d2)
5358 {
5359 switch(((int32_t*)dp3)[0])
5360 {
5361 case 0:
5362 midi_volume = zc_min(d2<<3,255);
5363 break;
5364
5365 case 1:
5366 digi_volume = zc_min(d2<<3,255);
5367 break;
5368
5369 case 2:
5370 emusic_volume = zc_min(d2<<3,255);
5371 break;
5372
5373 case 3:
5374 sfx_volume = zc_min(d2<<3,255);
5375 break;
5376 }
5377
5378 // text_mode(vc(11));
5379 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5380 return D_O_K;
5381 }
5382
5383 int32_t set_pan(void *dp3, int32_t d2)
5384 {
5385 pan_style = vbound(d2,0,3);
5386 // text_mode(vc(11));
5387 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5388 return D_O_K;
5389 }
5390
5391 static int32_t gamepad_joys_list[] =
5392 {
5393 61,
5394 -1
5395 };
5396
5397 static int32_t gamepad_btn_list[] =
5398 {
5399 6,
5400 7,8,9,10,11,12,13,14,15,16,17,
5401 18,19,20,21,22,23,24,25,26,27,28,
5402 29,30,31,32,33,34,35,36,37,38,39,
5403 -1
5404 };
5405
5406 static int32_t gamepad_dirs_list[] =
5407 {
5408 40,41,42,43,
5409 44,45,46,47,
5410 48,49,50,51,
5411 52,53,54,55,
5412 56,57,58,59,
5413 60,
5414 -1
5415 };
5416
5417 static TABPANEL gamepad_tabs[] =
5418 {
5419 // (text)
5420 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5421 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5422 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5423 { NULL, 0, NULL, 0, NULL }
5424 };
5425
5426 const char *joy_list(int32_t index, int32_t *list_size)
5427 {
5428 if (index == -1)
5429 {
5430 *list_size = al_get_num_joysticks();
5431 return NULL;
5432 }
5433
5434 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5435 if (!joy)
5436 {
5437 return "?";
5438 }
5439
5440 return al_get_joystick_name(joy);
5441 }
5442
5443 427 static ListData joy__list(joy_list, &font);
5444
5445 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5446 {
5447 int32_t d2 = d->d2;
5448 int32_t ret = jwin_droplist_proc(msg,d,c);
5449
5450 if(d2!=d->d2)
5451 {
5452 joystick_index = d->d2;
5453 ret |= D_REDRAW_ALL;
5454 }
5455
5456 return ret;
5457 }
5458
5459 static DIALOG gamepad_dlg[] =
5460 {
5461 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5462 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5463 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5464 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5465 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5466 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5467 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5468 // 6
5469 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5470 // 7
5471 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5472 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5473 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5474 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5475 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5476 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5477 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5478 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5479 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5480 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5481 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5482 // 18
5483 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5484 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5485 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5486 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5487 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5488 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5489 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5490 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5491 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5492 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5493 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5494 // 29
5495 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5496 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5497 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5498 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5499 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5500 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5501 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5502 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5503 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5504 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5505 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5506 // 40
5507 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5508 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5509 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5510 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5511 // 44
5512 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5513 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5514 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5515 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5516 // 48
5517 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5518 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5519 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5520 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5521 // 52
5522 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5523 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5524 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5525 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5526 // 56
5527 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5528 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5529 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5530 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5531 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5532
5533 // 61
5534 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5535
5536 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5537 };
5538
5539 static int32_t keyboard_keys_list[] =
5540 {
5541 6,7,8,9,10,
5542 11,12,13,14,15,16,17,18,19,20,
5543 21,22,23,24,25,26,27,28,29,30,
5544 31,32,33,34,35,36,37,38,39,40,
5545 -1
5546 };
5547
5548 static int32_t keyboard_dirs_list[] =
5549 {
5550 41,42,43,44,
5551 45,46,47,48,
5552 49,50,51,52,
5553 53,54,55,56,
5554 -1
5555 };
5556
5557 static int32_t keyboard_mods_list[] =
5558 {
5559 57,58,59,60,
5560 61,62,63,64,
5561 65,66,67,68,
5562 69,70,71,72,
5563 -1
5564 };
5565
5566 static TABPANEL keyboard_control_tabs[] =
5567 {
5568 // (text)
5569 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5570 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5571 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5572 { NULL, 0, NULL, 0, NULL }
5573 };
5574
5575 static DIALOG keyboard_control_dlg[] =
5576 {
5577 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5578 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5579 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5580 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5581 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5582 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5583 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5584 // Keys
5585 // 6
5586 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5587 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5588 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5589 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5590 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5591 // 11
5592 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5593 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5594 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5595 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5596 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5597 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5598 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5599 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5600 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5601 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5602 // 21
5603 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5604 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5605 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5606 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5607 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5608 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5609 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5610 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5611 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5612 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5613 // 31
5614 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5615 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5616 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5617 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5618 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5619 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5620 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5621 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5622 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5623 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5624 // Dirs
5625 // 41
5626 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5627 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5628 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5629 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5630 // 45
5631 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5632 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5633 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5634 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5635 // 49
5636 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5637 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5638 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5639 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5640 // 53
5641 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5642 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5643 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5644 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5645 // Mods
5646 // 57
5647 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5648 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5649 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5650 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5651 // 61
5652 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5653 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5654 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5655 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5656 // 65
5657 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5658 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5659 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5660 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5661 // 69
5662 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5663 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5664 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5665 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5666 // 73
5667 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5668 };
5669
5670 int32_t midi_dp[3] = {0,0,0};
5671 int32_t emus_dp[3] = {2,0,0};
5672 int32_t sfx_dp[3] = {3,0,0};
5673 int32_t pan_dp[3] = {0,0,0};
5674
5675 static DIALOG sound_dlg[] =
5676 {
5677 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5678 427 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5679 427 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5680 427 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5681 427 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5682 427 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5683 427 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5684 427 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5685 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5686 427 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5687 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5688 // 10
5689 427 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5690 427 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5691 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5692 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5693 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5694 427 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5695 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5696 427 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5697 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5698 427 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5699 //20
5700 427 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5701 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5702 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5703 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5704 427 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5705 427 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5706 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5707 427 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5708 427 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5709 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5710 //30
5711 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5712 427 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5713 427 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5714 };
5715
5716 char zc_builddate[80];
5717 char zc_aboutstr[80];
5718
5719 static DIALOG about_dlg[] =
5720 {
5721 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5722 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5723 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5724 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5725 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5726 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5727 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5728 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5729 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5730 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5731 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5732 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5733 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5734 };
5735
5736
5737 static DIALOG quest_dlg[] =
5738 {
5739 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5740 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5741 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5742 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5743 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5744 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5745 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5746 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5747 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5748 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5749 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5750 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5751 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5752 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5753 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5754 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5755 };
5756
5757 static DIALOG triforce_dlg[] =
5758 {
5759 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5760 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5761 // 1
5762 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5763 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5764 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5765 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5766 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5767 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5768 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5769 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5770 // 9
5771 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5772 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5773 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5774 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5775 };
5776
5777 int32_t onToggleRecordingNewSaves()
5778 {
5779 if (zc_get_config("zeldadx", "replay_new_saves", false))
5780 {
5781 zc_set_config("zeldadx", "replay_new_saves", false);
5782 }
5783 else
5784 {
5785 zc_set_config("zeldadx", "replay_new_saves", true);
5786 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5787 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5788 }
5789 return D_O_K;
5790 }
5791
5792 #ifdef HAS_CURL
5793 int32_t onToggleAutoUploadReplays()
5794 {
5795 if (zc_get_config("zeldadx", "replay_upload", false))
5796 {
5797 zc_set_config("zeldadx", "replay_upload", false);
5798 }
5799 else
5800 {
5801 zc_set_config("zeldadx", "replay_upload", true);
5802 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5803 " preventing bugs and simplifying bug reports.",
5804 "Upload will happen no more than once a week when closing ZC",
5805 "OK",NULL,13,27,get_zc_font(font_lfont));
5806
5807 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5808 onToggleRecordingNewSaves();
5809 }
5810 return D_O_K;
5811 }
5812
5813 int32_t onUploadReplays()
5814 {
5815 if(jwin_alert3(
5816 "Upload replays",
5817 "Upload your replays now to assist in development?",
5818 NULL,
5819 NULL,
5820 "&Yes",
5821 "&No",
5822 NULL,
5823 'y',
5824 'n',
5825 0,
5826 get_zc_font(font_lfont)) == 1)
5827 {
5828 int num_uploaded = replay_upload();
5829 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5830 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5831 }
5832 return D_O_K;
5833 }
5834
5835 int32_t onClearUploadCache()
5836 {
5837 if(jwin_alert3(
5838 "Upload replays",
5839 "Clear the upload cache?",
5840 "This simply deletes replays/state.json. There's no harm in doing this, but",
5841 "likely is not necessary.",
5842 "&Yes",
5843 "&No",
5844 NULL,
5845 'y',
5846 'n',
5847 0,
5848 get_zc_font(font_lfont)) == 1)
5849 {
5850 replay_upload_clear_cache();
5851 }
5852 return D_O_K;
5853 }
5854 #endif
5855
5856 int32_t onToggleSnapshotAllFrames()
5857 {
5858 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5859 return D_O_K;
5860 }
5861
5862 int32_t onStopReplayOrRecord()
5863 {
5864 if (replay_is_replaying())
5865 {
5866 replay_quit();
5867 }
5868 else if (replay_get_mode() == ReplayMode::Record)
5869 {
5870 if (!replay_get_meta_bool("test_mode"))
5871 {
5872 jwin_alert("Recording", "You cannot stop recording a save file.",
5873 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5874 return D_CLOSE;
5875 }
5876
5877 if (jwin_alert("Stop Recording",
5878 "Save replay to disk and stop recording?",
5879 "This will stop the recording.",
5880 NULL,
5881 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5882 return D_CLOSE;
5883
5884 replay_save();
5885 replay_stop();
5886 }
5887 return D_O_K;
5888 }
5889
5890 static int32_t handle_on_load_replay(ReplayMode mode)
5891 {
5892 bool ctrl = CHECK_CTRL_CMD;
5893 if (Playing)
5894 {
5895 if (jwin_alert("Replay - Warning!",
5896 "Loading a replay will exit the current game.",
5897 "All unsaved progress will be lost.",
5898 "Do you wish to continue?",
5899 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5900 return D_CLOSE;
5901 }
5902
5903 std::string mode_string = replay_mode_to_string(mode);
5904 mode_string[0] = std::toupper(mode_string[0]);
5905
5906 std::string line_1 = "Select a replay file to play back.";
5907 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5908 std::string line_3 = "You can stop the replay and take over manually any time.";
5909 if (mode == ReplayMode::Update)
5910 {
5911 line_1 = "Select a replay file to update.";
5912 line_2 = "WARNING: be sure to back up the zplay file";
5913 line_3 = "and verify that the updated replay works as expected!";
5914 }
5915
5916 if (jwin_alert(mode_string.c_str(),
5917 line_1.c_str(),
5918 line_2.c_str(),
5919 line_3.c_str(),
5920 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5921 {
5922 std::string replay_path = "replays/";
5923 if(ctrl && devpwd())
5924 replay_path = "../../tests/replays/";
5925 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5926 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5927 replay_path = *result;
5928 else
5929 return D_CLOSE;
5930
5931 replay_quit();
5932 load_replay_file_deferred(mode, replay_path);
5933 Quit = qRESET;
5934 return D_CLOSE;
5935 }
5936 return D_O_K;
5937 }
5938
5939 int32_t onLoadReplay()
5940 {
5941 return handle_on_load_replay(ReplayMode::Replay);
5942 }
5943
5944 int32_t onLoadReplayAssert()
5945 {
5946 return handle_on_load_replay(ReplayMode::Assert);
5947 }
5948
5949 int32_t onLoadReplayUpdate()
5950 {
5951 return handle_on_load_replay(ReplayMode::Update);
5952 }
5953
5954 int32_t onSaveReplay()
5955 {
5956 if (replay_get_mode() == ReplayMode::Record)
5957 {
5958 if (!replay_get_meta_bool("test_mode"))
5959 {
5960 if (jwin_alert("Save Replay",
5961 "This will save a copy of the replay up to this point.",
5962 "The official replay file will be untouched.",
5963 "Do you wish to continue?",
5964 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5965 {
5966 return D_CLOSE;
5967 }
5968
5969 std::string replay_path = replay_get_replay_path().string();
5970 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5971 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5972 replay_path = *result;
5973 else
5974 return D_CLOSE;
5975
5976 if (fileexists(replay_path.c_str()))
5977 {
5978 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5979 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5980 return D_CLOSE;
5981 }
5982
5983 replay_save(replay_path);
5984 }
5985 else
5986 {
5987 replay_save();
5988 }
5989 }
5990 return D_O_K;
5991 }
5992
5993 enum
5994 {
5995 MENUID_REPLAY_RECORDNEW,
5996 MENUID_REPLAY_STOP,
5997 MENUID_REPLAY_SAVE,
5998 MENUID_REPLAY_SNAP_ALL,
5999 MENUID_REPLAY_AUTOUPLOAD,
6000 MENUID_REPLAY_UPLOAD,
6001 MENUID_REPLAY_CLEARUPLOADCACHE,
6002 };
6003
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu replay_menu
6004 5551 {
6005
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
6006
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 {},
6007
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
6008
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Load replay", onLoadReplay },
6009
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Load replay (assert)", onLoadReplayAssert },
6010
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Load replay (update)", onLoadReplayUpdate },
6011
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
6012
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
6013 #ifdef HAS_CURL
6014
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 {},
6015
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
6016
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
6017
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
6018 #endif
6019 };
6020
6021 static DIALOG credits_dlg[] =
6022 {
6023 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6024 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6025 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6026 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6027 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6028 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6029 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6030 };
6031
6032 427 static ListData dmap_list(dmaplist, &font);
6033
6034 static DIALOG goto_dlg[] =
6035 {
6036 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6037 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6038 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6039 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6040 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6041 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6042 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6043 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6044 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6045 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6046 };
6047
6048 int32_t onGoTo()
6049 {
6050 bool music = false;
6051 music = music;
6052 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6053
6054 goto_dlg[0].dp2=get_zc_font(font_lfont);
6055 goto_dlg[4].d2=cheat_goto_dmap;
6056 goto_dlg[6].dp=cheat_goto_screen_str;
6057
6058 clear_keybuf();
6059
6060 large_dialog(goto_dlg);
6061
6062 if(do_zqdialog(goto_dlg,4)==1)
6063 {
6064 int dmap = goto_dlg[4].d2;
6065 int screen = zc_xtoi(cheat_goto_screen_str);
6066 int adjusted_screen = screen + DMaps[dmap].xoff;
6067 if (adjusted_screen < 0 || adjusted_screen >= 128)
6068 {
6069 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6070 }
6071 else
6072 {
6073 cheats_enqueue(Cheat::GoTo, dmap, screen);
6074 }
6075 };
6076
6077 return D_O_K;
6078 }
6079
6080 int32_t onGoToComplete()
6081 {
6082 if(!Playing)
6083 {
6084 return D_O_K;
6085 }
6086
6087 enter_sys_pal();
6088 music_pause();
6089 pause_all_sfx();
6090 onGoTo();
6091 eat_buttons();
6092
6093 zc_readrawkey(KEY_ESC);
6094
6095 exit_sys_pal();
6096 music_resume();
6097 resume_all_sfx();
6098 return D_O_K;
6099 }
6100
6101 int32_t onCredits()
6102 {
6103 return D_O_K;
6104 }
6105
6106 const char *midilist(int32_t index, int32_t *list_size)
6107 {
6108 if(index<0)
6109 {
6110 *list_size=0;
6111
6112 for(int32_t i=0; i<MAXMIDIS; i++)
6113 if(tunes[i].data)
6114 ++(*list_size);
6115
6116 return NULL;
6117 }
6118
6119 int32_t i=0,m=0;
6120
6121 while(m<=index && i<=MAXMIDIS)
6122 {
6123 if(tunes[i].data)
6124 ++m;
6125
6126 ++i;
6127 }
6128
6129 --i;
6130
6131 if(i==MAXMIDIS && m<index)
6132 return "(null)";
6133
6134 return tunes[i].title;
6135 }
6136
6137 /* ------- MIDI info stuff -------- */
6138
6139 char *text;
6140 midi_info *zmi;
6141 bool dialog_running;
6142 bool listening;
6143
6144 void get_info(int32_t index);
6145
6146 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6147 {
6148 int32_t d2 = d->d2;
6149 int32_t ret = jwin_droplist_proc(msg,d,c);
6150
6151 if(d2!=d->d2)
6152 {
6153 get_info(d->d2);
6154 }
6155
6156 return ret;
6157 }
6158
6159 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6160 {
6161 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6162
6163 int32_t ret = jwin_button_proc(msg,d,c);
6164
6165 if(ret == D_CLOSE)
6166 {
6167 // get current midi index
6168 int32_t index = (d+(d->d1))->d2;
6169 int32_t i=0, m=0;
6170
6171 while(m<=index && i<=MAXMIDIS)
6172 {
6173 if(tunes[i].data)
6174 ++m;
6175
6176 ++i;
6177 }
6178
6179 --i;
6180 jukebox(i);
6181 listening = true;
6182 ret = D_O_K;
6183 }
6184
6185 return ret;
6186 }
6187
6188 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6189 {
6190 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6191
6192 int32_t ret = jwin_button_proc(msg,d,c);
6193
6194 if(ret == D_CLOSE)
6195 {
6196 // get current midi index
6197 int32_t index = (d+(d->d1))->d2;
6198 int32_t i=0, m=0;
6199
6200 while(m<=index && i<=MAXMIDIS)
6201 {
6202 if(tunes[i].data)
6203 ++m;
6204
6205 ++i;
6206 }
6207
6208 --i;
6209
6210 char title[40] = "Save MIDI: ";
6211 static EXT_LIST list[] =
6212 {
6213 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6214 { NULL, NULL }
6215 };
6216
6217 strcpy(title+11, tunes[i].title);
6218 title[39] = '\0';
6219
6220 std::string fname;
6221 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6222 fname = *result;
6223 else
6224 goto done;
6225
6226 if(exists(fname.c_str()))
6227 {
6228 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6229 goto done;
6230 }
6231
6232 // save midi i
6233
6234 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6235 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6236
6237 done:
6238 chop_path(fname.data());
6239 ret = D_REDRAW;
6240 }
6241
6242 return ret;
6243 }
6244
6245 427 static ListData midi_list(midilist, &font);
6246
6247 static DIALOG midi_dlg[] =
6248 {
6249 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6250 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6251 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6252 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6253 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6254 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6255 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6256 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6257 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6258 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6259 };
6260
6261 void get_info(int32_t index)
6262 {
6263 int32_t i=0, m=0;
6264
6265 while(m<=index && i<=MAXMIDIS)
6266 {
6267 if(tunes[i].data)
6268 ++m;
6269
6270 ++i;
6271 }
6272
6273 --i;
6274
6275 if(i==MAXMIDIS && m<index)
6276 strcpy(text,"(null)");
6277 else
6278 {
6279 get_midi_info(tunes[i].data,zmi);
6280 get_midi_text(tunes[i].data,zmi,text);
6281 }
6282
6283 midi_dlg[0].dp2=get_zc_font(font_lfont);
6284 midi_dlg[3].dp = text;
6285 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6286 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6287
6288 if(dialog_running)
6289 {
6290 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6291 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6292 }
6293 }
6294
6295 int32_t onMIDICredits()
6296 {
6297 text = (char*)malloc(4096);
6298 zmi = (midi_info*)malloc(sizeof(midi_info));
6299
6300 if(!text || !zmi)
6301 {
6302 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6303 return D_O_K;
6304 }
6305
6306 bool do_pause_midi = midi_pos >= 0 && currmidi;
6307 auto restore_midi = currmidi;
6308 if(do_pause_midi)
6309 {
6310 paused_midi_pos = midi_pos;
6311 stop_midi();
6312 midi_suspended = midissuspHALTED;
6313 }
6314
6315 midi_dlg[0].dp2=get_zc_font(font_lfont);
6316 midi_dlg[2].d1 = 0;
6317 midi_dlg[2].d2 = 0;
6318 midi_dlg[4].flags = D_EXIT;
6319 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6320
6321 listening = false;
6322 dialog_running=false;
6323 get_info(0);
6324
6325 dialog_running=true;
6326
6327 large_dialog(midi_dlg);
6328
6329 do_zqdialog(midi_dlg,0);
6330 dialog_running=false;
6331
6332 if(listening)
6333 music_stop();
6334
6335 if(do_pause_midi)
6336 {
6337 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6338 midi_suspended = midissuspRESUME;
6339 currmidi = restore_midi;
6340 midi_pos = paused_midi_pos;
6341 }
6342
6343 if(text) free(text);
6344 if(zmi) free(zmi);
6345 return D_O_K;
6346 }
6347
6348 int32_t onAbout()
6349 {
6350 char buf1[80]={0};
6351 std::ostringstream oss;
6352 sprintf(buf1,"ZQuest Classic Player");
6353 oss << buf1 << '\n';
6354 sprintf(buf1,"Version: %s", getVersionString());
6355 oss << buf1 << '\n';
6356 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6357 oss << buf1 << '\n';
6358
6359 InfoDialog("About ZC", oss.str()).show();
6360 return D_O_K;
6361 }
6362
6363 int32_t onQuest()
6364 {
6365 char fname[100];
6366 strcpy(fname, get_filename(qstpath));
6367 quest_dlg[0].dp2=get_zc_font(font_lfont);
6368 quest_dlg[1].dp = fname;
6369
6370 if(QHeader.quest_number==0)
6371 sprintf(str_a,"Custom");
6372 else
6373 sprintf(str_a,"%d",QHeader.quest_number);
6374
6375 sprintf(str_s,"%s",QHeader.getVerStr());
6376
6377 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6378 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6379
6380 large_dialog(quest_dlg);
6381
6382 do_zqdialog(quest_dlg, 0);
6383 return D_O_K;
6384 }
6385
6386 void call_vidmode_dlg();
6387 int32_t onVidMode()
6388 {
6389 call_vidmode_dlg();
6390 return D_O_K;
6391 }
6392
6393 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6394 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6395 //Added an extra statement, so that if the key is cleared to 0, the cleared
6396 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6397
6398 void load_ukeys(int32_t* arr)
6399 {
6400 arr[ukey_a] = Akey;
6401 arr[ukey_b] = Bkey;
6402 arr[ukey_s] = Skey;
6403 arr[ukey_l] = Lkey;
6404 arr[ukey_r] = Rkey;
6405 arr[ukey_p] = Pkey;
6406 arr[ukey_ex1] = Exkey1;
6407 arr[ukey_ex2] = Exkey2;
6408 arr[ukey_ex3] = Exkey3;
6409 arr[ukey_ex4] = Exkey4;
6410 arr[ukey_du] = DUkey;
6411 arr[ukey_dd] = DDkey;
6412 arr[ukey_dl] = DLkey;
6413 arr[ukey_dr] = DRkey;
6414 arr[ukey_mod1a] = cheat_modifier_keys[0];
6415 arr[ukey_mod1b] = cheat_modifier_keys[1];
6416 arr[ukey_mod2a] = cheat_modifier_keys[2];
6417 arr[ukey_mod2b] = cheat_modifier_keys[3];
6418 };
6419
6420 static const char* ukey_names[] = {
6421 "A", "B", "Start", "L", "R", "Map",
6422 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6423 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6424 "Cheat Mod R1", "Cheat Mod R2",
6425 };
6426 std::string get_ukey_name(int32_t k)
6427 {
6428 if (k < num_ukey) return ukey_names[k];
6429 return "";
6430 }
6431
6432 int32_t onKeyboard()
6433 {
6434 int32_t a = Akey;
6435 int32_t b = Bkey;
6436 int32_t s = Skey;
6437 int32_t l = Lkey;
6438 int32_t r = Rkey;
6439 int32_t p = Pkey;
6440 int32_t ex1 = Exkey1;
6441 int32_t ex2 = Exkey2;
6442 int32_t ex3 = Exkey3;
6443 int32_t ex4 = Exkey4;
6444 int32_t du = DUkey;
6445 int32_t dd = DDkey;
6446 int32_t dl = DLkey;
6447 int32_t dr = DRkey;
6448 int32_t mod1a = cheat_modifier_keys[0];
6449 int32_t mod1b = cheat_modifier_keys[1];
6450 int32_t mod2a = cheat_modifier_keys[2];
6451 int32_t mod2b = cheat_modifier_keys[3];
6452 bool done=false;
6453 int32_t ret;
6454
6455 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6456
6457 large_dialog(keyboard_control_dlg);
6458
6459 while(!done)
6460 {
6461 ret = do_zqdialog(keyboard_control_dlg,3);
6462
6463 if(ret==3) // OK
6464 {
6465 int32_t ukeys[num_ukey];
6466 load_ukeys(ukeys);
6467 std::vector<std::string> uniqueError;
6468 for(int32_t q = 0; q < num_ukey; ++q)
6469 {
6470 for(int32_t p = q+1; p < num_ukey; ++p)
6471 {
6472 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6473 {
6474 char buf[64];
6475 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6476 std::string str(buf);
6477 uniqueError.push_back(str);
6478 }
6479 }
6480 }
6481 if(uniqueError.size() == 0)
6482 {
6483 done = true;
6484 save_control_configs(true);
6485 }
6486 else
6487 {
6488 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6489 box_out("Cannot have duplicate keybinds!"); box_eol();
6490 for(std::vector<std::string>::iterator it = uniqueError.begin();
6491 it != uniqueError.end(); ++it)
6492 {
6493 box_out((*it).c_str()); box_eol();
6494 }
6495 box_end(true);
6496 }
6497 }
6498 else // Cancel
6499 {
6500 Akey = a;
6501 Bkey = b;
6502 Skey = s;
6503 Lkey = l;
6504 Rkey = r;
6505 Pkey = p;
6506 Exkey1 = ex1;
6507 Exkey2 = ex2;
6508 Exkey3 = ex3;
6509 Exkey4 = ex4;
6510 DUkey = du;
6511 DDkey = dd;
6512 DLkey = dl;
6513 DRkey = dr;
6514 cheat_modifier_keys[0] = mod1a;
6515 cheat_modifier_keys[1] = mod1b;
6516 cheat_modifier_keys[2] = mod2a;
6517 cheat_modifier_keys[3] = mod2b;
6518
6519 done=true;
6520 }
6521
6522 rest(1);
6523 }
6524
6525 return D_O_K;
6526 }
6527
6528 int32_t onGamepad()
6529 {
6530 if (al_get_num_joysticks() == 0)
6531 {
6532 InfoDialog("ZC", "No gamepads detected.").show();
6533 return D_O_K;
6534 }
6535
6536 int32_t a = Abtn;
6537 int32_t b = Bbtn;
6538 int32_t s = Sbtn;
6539 int32_t l = Lbtn;
6540 int32_t r = Rbtn;
6541 int32_t m = Mbtn;
6542 int32_t p = Pbtn;
6543 int32_t ex1 = Exbtn1;
6544 int32_t ex2 = Exbtn2;
6545 int32_t ex3 = Exbtn3;
6546 int32_t ex4 = Exbtn4;
6547 int32_t up = DUbtn;
6548 int32_t down = DDbtn;
6549 int32_t left = DLbtn;
6550 int32_t right = DRbtn;
6551 int32_t joy = joystick_index;
6552 int32_t stick_1 = js_stick_1_x_stick;
6553 int32_t stick_2 = js_stick_2_x_stick;
6554
6555 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6556 if(analog_movement)
6557 gamepad_dlg[56].flags|=D_SELECTED;
6558 else
6559 gamepad_dlg[56].flags&=~D_SELECTED;
6560
6561 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6562 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6563 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6564 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6565 // requires remapping every time.
6566 if (joystick_index >= al_get_num_joysticks())
6567 joystick_index = 0;
6568 gamepad_dlg[61].d2 = joystick_index;
6569
6570 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6571 if (!gamepad_dlg_cur_joystick)
6572 {
6573 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6574 return D_CLOSE;
6575 }
6576
6577 large_dialog(gamepad_dlg);
6578
6579 int32_t ret = do_zqdialog(gamepad_dlg,4);
6580
6581 if(ret == 4) //OK
6582 {
6583 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6584 joystick_index = gamepad_dlg[61].d2;
6585 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6586 if (!gamepad_dlg_cur_joystick)
6587 {
6588 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6589 return D_CLOSE;
6590 }
6591 js_stick_1_y_stick = js_stick_1_x_stick;
6592 js_stick_2_y_stick = js_stick_2_x_stick;
6593 save_control_configs(false);
6594 }
6595 else //Cancel
6596 {
6597 Abtn = a;
6598 Bbtn = b;
6599 Sbtn = s;
6600 Lbtn = l;
6601 Rbtn = r;
6602 Mbtn = m;
6603 Pbtn = p;
6604 Exbtn1 = ex1;
6605 Exbtn2 = ex2;
6606 Exbtn3 = ex3;
6607 Exbtn4 = ex4;
6608 DUbtn = up;
6609 DDbtn = down;
6610 DLbtn = left;
6611 DRbtn = right;
6612 joystick_index = joy;
6613 js_stick_1_x_stick = stick_1;
6614 js_stick_2_x_stick = stick_2;
6615 }
6616
6617 return D_O_K;
6618 }
6619
6620 int32_t onCheatKeys()
6621 {
6622 int32_t oldcheats[Cheat::Last][2];
6623 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6624
6625 bool done=false;
6626
6627 while(!done)
6628 {
6629 bool confirm = false;
6630 CheatKeysDialog(&confirm).show();
6631 if(confirm) // OK
6632 {
6633 std::vector<std::string> uniqueError;
6634 char buf[512];
6635 for(size_t q = 1; q < Cheat::Last; ++q)
6636 {
6637 if(cheatkeys[q][1] && !cheatkeys[q][0])
6638 {
6639 cheatkeys[q][0] = cheatkeys[q][1];
6640 cheatkeys[q][1] = 0;
6641 }
6642 }
6643 for(size_t q = 1; q < Cheat::Last; ++q)
6644 {
6645 if(!bindable_cheat((Cheat)q)) continue;
6646 for(size_t p = q+1; p < Cheat::Last; ++p)
6647 {
6648 if(!bindable_cheat((Cheat)p)) continue;
6649 for(size_t q2 = 0; q2 <= 1; ++q2)
6650 for(size_t p2 = 0; p2 <= 1; ++p2)
6651 {
6652 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6653 {
6654 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6655 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6656 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6657 get_keystr(cheatkeys[q][q2])));
6658 }
6659 }
6660 }
6661 }
6662 if(uniqueError.size() == 0)
6663 {
6664 done = true;
6665 save_cheatkeys();
6666 }
6667 else
6668 {
6669 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6670 box_out("Cannot have duplicate keybinds!"); box_eol();
6671 for(std::vector<std::string>::iterator it = uniqueError.begin();
6672 it != uniqueError.end(); ++it)
6673 {
6674 box_out((*it).c_str()); box_eol();
6675 }
6676 box_end(true);
6677 }
6678 }
6679 else // Cancel
6680 {
6681 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6682 done=true;
6683 }
6684 rest(1);
6685 }
6686
6687 return D_O_K;
6688 }
6689
6690 int32_t onSound()
6691 {
6692 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6693 {
6694 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6695 {
6696 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6697 }
6698 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6699 {
6700 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6701 }
6702 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6703 {
6704 emusic_volume = (int32_t)FFCore.usr_music_volume;
6705 }
6706 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6707 {
6708 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6709 }
6710 }
6711 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6712 {
6713 pan_style = (int32_t)FFCore.usr_panstyle;
6714 }
6715
6716 int32_t m = midi_volume;
6717 int32_t e = emusic_volume;
6718 int32_t s = sfx_volume;
6719 int32_t p = pan_style;
6720 pan_style = vbound(pan_style,0,3);
6721
6722 sound_dlg[0].dp2=get_zc_font(font_lfont);
6723
6724 large_dialog(sound_dlg);
6725
6726 midi_dp[1] = sound_dlg[6].x;
6727 midi_dp[2] = sound_dlg[6].y;
6728 emus_dp[1] = sound_dlg[8].x;
6729 emus_dp[2] = sound_dlg[8].y;
6730 sfx_dp[1] = sound_dlg[10].x;
6731 sfx_dp[2] = sound_dlg[10].y;
6732 pan_dp[1] = sound_dlg[11].x;
6733 pan_dp[2] = sound_dlg[11].y;
6734 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6735 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6736 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6737 sound_dlg[20].d2 = pan_style;
6738
6739 int32_t ret = do_zqdialog(sound_dlg,1);
6740
6741 if(ret==2)
6742 {
6743 master_volume(digi_volume,midi_volume);
6744 if (zcmusic)
6745 zcmusic_set_volume(zcmusic, emusic_volume);
6746
6747 int32_t temp_volume = sfx_volume;
6748 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6749 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6750 for(int32_t i=0; i<WAV_COUNT; ++i)
6751 {
6752 if(sfx_voice[i] >= 0)
6753 voice_set_volume(sfx_voice[i], temp_volume);
6754 }
6755 zc_set_config(sfx_sect,"midi",midi_volume);
6756 zc_set_config(sfx_sect,"sfx",sfx_volume);
6757 zc_set_config(sfx_sect,"emusic",emusic_volume);
6758 zc_set_config(sfx_sect,"pan",pan_style);
6759 }
6760 else
6761 {
6762 midi_volume = m;
6763 emusic_volume = e;
6764 sfx_volume = s;
6765 pan_style = p;
6766 }
6767
6768 return D_O_K;
6769 }
6770
6771 int32_t queding(char const* s1, char const* s2, char const* s3)
6772 {
6773 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6774 }
6775
6776 int32_t onQuit()
6777 {
6778 if(Playing)
6779 {
6780 int32_t ret=0;
6781
6782 if(get_qr(qr_NOCONTINUE))
6783 {
6784 if(standalone_mode)
6785 {
6786 ret=queding("End current game?",
6787 "The continue screen is disabled; the game",
6788 "will be reloaded from the last save.");
6789 }
6790 else
6791 {
6792 ret=queding("End current game?",
6793 "The continue screen is disabled. You will",
6794 "be returned to the file select screen.");
6795 }
6796 }
6797 else
6798 ret=queding("End current game?",NULL,NULL);
6799
6800 if(ret==1)
6801 {
6802 disableClickToFreeze=false;
6803 Quit=qQUIT;
6804
6805 // Trying to evade a door repair charge?
6806 if(repaircharge)
6807 {
6808 game->change_drupy(-repaircharge);
6809 repaircharge=0;
6810 }
6811
6812 return D_CLOSE;
6813 }
6814 }
6815
6816 return D_O_K;
6817 }
6818
6819 int32_t onTryQuitMenu()
6820 {
6821 return onTryQuit(true);
6822 }
6823
6824 int32_t onTryQuit(bool inMenu)
6825 {
6826 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6827 {
6828 if(active_cutscene.can_f6())
6829 {
6830 if(get_qr(qr_OLD_F6))
6831 {
6832 if(inMenu) onQuit();
6833 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6834 }
6835 else
6836 {
6837 disableClickToFreeze=false;
6838 GameFlags |= GAMEFLAG_TRYQUIT;
6839 }
6840 return D_CLOSE;
6841 }
6842 else active_cutscene.error();
6843 }
6844
6845 return D_O_K;
6846 }
6847
6848 int32_t onReset()
6849 {
6850 if(queding(" Reset system? ",NULL,NULL)==1)
6851 {
6852 disableClickToFreeze=false;
6853 Quit=qRESET;
6854 replay_quit();
6855 return D_CLOSE;
6856 }
6857
6858 return D_O_K;
6859 }
6860
6861 int32_t onExit()
6862 {
6863 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6864 {
6865 Quit=qEXIT;
6866 return D_CLOSE;
6867 }
6868
6869 return D_O_K;
6870 }
6871
6872 int32_t onDebug()
6873 {
6874 if(debug_enabled)
6875 set_debug(!get_debug());
6876 return D_O_K;
6877 }
6878
6879 int32_t onHeartBeep()
6880 {
6881 heart_beep=!heart_beep;
6882 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6883 return D_O_K;
6884 }
6885
6886 int32_t onSaveIndicator()
6887 {
6888 use_save_indicator = use_save_indicator ? 0 : 1;
6889 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6890 return D_O_K;
6891 }
6892
6893 int32_t onEpilepsy()
6894 {
6895 if(jwin_alert3(
6896 "Epilepsy Flash Reduction",
6897 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6898 "Disabling this will restore standard flash and wavy behaviour.",
6899 "Proceed?",
6900 "&Yes",
6901 "&No",
6902 NULL,
6903 'y',
6904 'n',
6905 0,
6906 get_zc_font(font_lfont)) == 1)
6907 {
6908 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6909 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6910 }
6911 return D_O_K;
6912 }
6913
6914 bool rc = false;
6915
6916 static DIALOG getnum_dlg[] =
6917 {
6918 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6919 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6920 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6921 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6922 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6923 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6924 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6925 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6926 };
6927
6928 int32_t getnumber(const char *prompt,int32_t initialval)
6929 {
6930 char buf[20];
6931 sprintf(buf,"%d",initialval);
6932 getnum_dlg[0].dp=(void *)prompt;
6933 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6934 getnum_dlg[2].dp=buf;
6935
6936 large_dialog(getnum_dlg);
6937
6938 if(do_zqdialog(getnum_dlg,2)==3)
6939 return atoi(buf);
6940
6941 return initialval;
6942 }
6943
6944 int32_t onLife()
6945 {
6946 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6947 cheats_enqueue(Cheat::Life, value);
6948 return D_O_K;
6949 }
6950
6951 int32_t onHeartC()
6952 {
6953 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6954 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6955 cheats_enqueue(Cheat::MaxLife, max_life);
6956 cheats_enqueue(Cheat::Life, life);
6957 return D_O_K;
6958 }
6959
6960 int32_t onMagicC()
6961 {
6962 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6963 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6964 cheats_enqueue(Cheat::MaxMagic, max_magic);
6965 cheats_enqueue(Cheat::Magic, magic);
6966 return D_O_K;
6967 }
6968
6969 int32_t onRupies()
6970 {
6971 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6972 cheats_enqueue(Cheat::Rupies, value);
6973 return D_O_K;
6974 }
6975
6976 int32_t onMaxBombs()
6977 {
6978 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6979 cheats_enqueue(Cheat::MaxBombs, value);
6980 cheats_enqueue(Cheat::Bombs, value);
6981 return D_O_K;
6982 }
6983
6984 int32_t onRefillLife()
6985 {
6986 cheats_enqueue(Cheat::Life, game->get_maxlife());
6987 return D_O_K;
6988 }
6989 int32_t onRefillMagic()
6990 {
6991 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
6992 return D_O_K;
6993 }
6994 int32_t onClock()
6995 {
6996 cheats_enqueue(Cheat::Clock);
6997 return D_O_K;
6998 }
6999
7000 int32_t onQstPath()
7001 {
7002 char initial_path[2048];
7003 chop_path(qstdir);
7004 strcpy(initial_path, qstdir);
7005
7006 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
7007 {
7008 char* path = result->data();
7009 chop_path(path);
7010 fix_filename_case(path);
7011 fix_filename_slashes(path);
7012 strcpy(qstdir,path);
7013 strcpy(qstpath,qstdir);
7014 zc_set_config("zeldadx","quest_dir",qstdir);
7015 flush_config_file();
7016 }
7017
7018 return D_O_K;
7019 }
7020
7021 #include "dialog/cheat_dialog.h"
7022 int32_t onCheat()
7023 {
7024 call_setcheat_dialog();
7025 game->set_cheat(maxcheat);
7026 if(cheat) game->did_cheat(true);
7027 return D_O_K;
7028 }
7029
7030 int32_t onCheatRupies()
7031 {
7032 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7033 return D_O_K;
7034 }
7035
7036 int32_t onCheatArrows()
7037 {
7038 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7039 return D_O_K;
7040 }
7041
7042 int32_t onCheatBombs()
7043 {
7044 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7045 return D_O_K;
7046 }
7047
7048 // *** screen saver
7049
7050 19229703 int32_t after_time()
7051 {
7052
1/2
✓ Branch 0 taken 19229703 times.
✗ Branch 1 not taken.
19229703 if(ss_enable == 0)
7053 return INT_MAX;
7054
7055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19229703 times.
19229703 if(ss_after <= 0)
7056 return 5 * 60;
7057
7058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19229703 times.
19229703 if(ss_after <= 3)
7059 return ss_after * 15 * 60;
7060
7061
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19229703 times.
19229703 if(ss_after <= 13)
7062 return (ss_after - 3) * 60 * 60;
7063
7064 19229703 return MAX_IDLE + 1;
7065 19229703 }
7066
7067 static const char *after_str[15] =
7068 {
7069 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7070 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7071 "Never"
7072 };
7073
7074 const char *after_list(int32_t index, int32_t *list_size)
7075 {
7076 if(index < 0)
7077 {
7078 *list_size = 15;
7079 return NULL;
7080 }
7081
7082 return after_str[index];
7083 }
7084
7085 427 static ListData after__list(after_list, &font);
7086
7087 static DIALOG scrsaver_dlg[] =
7088 {
7089 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7090 427 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7091 427 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7092 427 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7093 427 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7094 427 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7095 427 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7096 427 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7097 427 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7098 427 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7099 427 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7100 427 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7101 427 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7102 427 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7103 };
7104
7105 int32_t onScreenSaver()
7106 {
7107 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7108 int32_t oldcfgs[3];
7109 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7110 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7111 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7112
7113 large_dialog(scrsaver_dlg);
7114
7115 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7116
7117 if(ret == 8 || ret == 9)
7118 {
7119 ss_after = scrsaver_dlg[5].d1;
7120 ss_speed = scrsaver_dlg[6].d2;
7121 ss_density = scrsaver_dlg[7].d2;
7122 if(oldcfgs[0] != ss_after)
7123 zc_set_config(cfg_sect,"ss_after",ss_after);
7124 if(oldcfgs[1] != ss_speed)
7125 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7126 if(oldcfgs[2] != ss_density)
7127 zc_set_config(cfg_sect,"ss_density",ss_density);
7128 }
7129
7130 if(ret == 9)
7131 // preview Screen Saver
7132 {
7133 clear_keybuf();
7134 Matrix(ss_speed, ss_density, 30);
7135 system_pal(true);
7136 sys_mouse();
7137 }
7138
7139 return D_O_K;
7140 }
7141
7142 /***** Menus *****/
7143
7144 enum
7145 {
7146 MENUID_GAME_LOADQUEST,
7147 MENUID_GAME_ENDGAME,
7148 };
7149
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu game_menu
7150 3416 {
7151
3/6
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
427 { "&Continue","ESC", onContinue },
7152
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 {},
7153
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7154
3/6
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
427 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7155
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 {},
7156 #ifdef __EMSCRIPTEN__
7157 { "&Reset","F7", onReset },
7158 #elif defined(ALLEGRO_MACOSX)
7159 { "&Reset","F7", onReset },
7160 { "&Quit","F8", onExit },
7161 #else
7162
3/6
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
427 { "&Reset","F9", onReset },
7163
3/6
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
427 { "&Quit","F10", onExit },
7164 #endif
7165 };
7166
7167
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu snapshot_format_menu
7168 2989 {
7169
4/8
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 427 times.
✗ Branch 7 not taken.
427 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7170
4/8
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 427 times.
✗ Branch 7 not taken.
427 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7171
4/8
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 427 times.
✗ Branch 7 not taken.
427 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7172
4/8
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 427 times.
✗ Branch 7 not taken.
427 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7173
4/8
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 427 times.
✗ Branch 7 not taken.
427 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7174
4/8
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 427 times.
✗ Branch 7 not taken.
427 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7175 };
7176
7177
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu bottom_8_pixels_menu
7178 1708 {
7179
4/8
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 427 times.
✗ Branch 7 not taken.
427 { "&Default (qst)", std::bind(onSetBottom8Pixels, 0) },
7180
4/8
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 427 times.
✗ Branch 7 not taken.
427 { "&On", std::bind(onSetBottom8Pixels, 1) },
7181
4/8
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 427 times.
✗ Branch 7 not taken.
427 { "&Off", std::bind(onSetBottom8Pixels, 2) },
7182 };
7183
7184
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu controls_menu
7185 1708 {
7186
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Key&board...", onKeyboard },
7187
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Gamepad...", onGamepad },
7188
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Cheat Keys...", onCheatKeys },
7189 };
7190
7191
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu name_entry_mode_menu
7192 1708 {
7193
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Keyboard", onKeyboardEntry },
7194
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Letter Grid", onLetterGridEntry },
7195
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Extended Letter Grid", onExtLetterGridEntry },
7196 };
7197
7198 static void set_controls_menu_active()
7199 {
7200
7201 }
7202
7203 enum
7204 {
7205 MENUID_WINDOW_LOCK_ASPECT,
7206 MENUID_WINDOW_LOCK_INTSCALE,
7207 MENUID_WINDOW_SAVE_SIZE,
7208 MENUID_WINDOW_SAVE_POS,
7209 MENUID_WINDOW_STRETCH,
7210 };
7211
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu window_menu
7212 2562 {
7213
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7214
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7215
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7216
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7217
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7218 };
7219 void call_zc_options_dlg();
7220 enum
7221 {
7222 MENUID_OPTIONS_PAUSE_BG,
7223 MENUID_OPTIONS_EPILEPSYPROT,
7224 MENUID_OPTIONS_SHOWBOTTOMPIXELS,
7225 };
7226
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu options_menu
7227 3416 {
7228
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Name &Entry Mode", &name_entry_mode_menu },
7229
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "S&napshot Format", &snapshot_format_menu },
7230
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Window Settings", &window_menu },
7231
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7232
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7233
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Show Bottom 8 Pixels", &bottom_8_pixels_menu, MENUID_OPTIONS_SHOWBOTTOMPIXELS },
7234
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "More Options", call_zc_options_dlg },
7235 };
7236 enum
7237 {
7238 MENUID_SETTINGS_CONTROLS,
7239 MENUID_SETTINGS_CAPFPS,
7240 MENUID_SETTINGS_SHOWFPS,
7241 MENUID_SETTINGS_SHOWTIME,
7242 MENUID_SETTINGS_CLICK_FREEZE,
7243 MENUID_SETTINGS_TRANSLAYERS,
7244 MENUID_SETTINGS_NESQUIT,
7245 MENUID_SETTINGS_VOLKEYS,
7246 MENUID_SETTINGS_HEARTBEEP,
7247 MENUID_SETTINGS_SAVEINDICATOR,
7248 MENUID_SETTINGS_DEBUG,
7249 };
7250
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu settings_menu
7251 7259 {
7252
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Sound...", onSound },
7253
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7254
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 {},
7255
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Options", &options_menu },
7256
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 {},
7257
3/6
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
427 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7258
3/6
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 427 times.
✗ Branch 5 not taken.
427 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7259
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7260
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7261
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7262
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7263
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7264
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7265
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7266
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 {},
7267
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7268 };
7269
7270 enum
7271 {
7272 MENUID_MISC_FULLSCREEN,
7273 MENUID_MISC_VIDMODE,
7274 MENUID_MISC_QUEST_INFO,
7275 MENUID_MISC_QUEST_DIR,
7276 MENUID_MISC_CONSOLE,
7277 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7278 };
7279
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu misc_menu
7280 6405 {
7281
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&About...", onAbout },
7282 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7283 // { "&Credits...", onCredits },
7284
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7285
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7286
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 {},
7287
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7288
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Quest &MIDI Info...", onMIDICredits },
7289
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7290
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 {},
7291
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Take &Snapshot F12", onSnapshot },
7292
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Sc&reen Saver...", onScreenSaver },
7293
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Save ZC Configuration", OnSaveZCConfig },
7294
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7295
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7296
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Clear Directory Cache", OnnClearQuestDir },
7297 };
7298
7299 enum
7300 {
7301 MENUID_REFILL_ARROWS,
7302 };
7303
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu refill_menu
7304 2562 {
7305
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Life", onRefillLife },
7306
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Magic", onRefillMagic },
7307
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Bombs", onCheatBombs },
7308
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Rupees", onCheatRupies },
7309
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7310 };
7311
7312 enum
7313 {
7314 MENUID_SHOW_L0,
7315 MENUID_SHOW_L1,
7316 MENUID_SHOW_L2,
7317 MENUID_SHOW_L3,
7318 MENUID_SHOW_L4,
7319 MENUID_SHOW_L5,
7320 MENUID_SHOW_L6,
7321 MENUID_SHOW_OVER,
7322 MENUID_SHOW_PUSH,
7323 MENUID_SHOW_FFC,
7324 MENUID_SHOW_SPR,
7325 MENUID_SHOW_SCRIPTNAME,
7326 MENUID_SHOW_SOLIDITY,
7327 MENUID_SHOW_HITBOX,
7328 MENUID_SHOW_EFFECT,
7329 };
7330
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu show_menu
7331 8113 {
7332
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7333
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7334
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7335
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7336
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7337
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7338
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7339
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7340
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7341
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7342
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7343
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 {},
7344
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7345
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 {},
7346
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7347
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7348
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7349
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Info Opacity", onShowInfoOpacity },
7350 };
7351
7352 enum
7353 {
7354 MENUID_CHEAT_CHOP_L1,
7355 MENUID_CHEAT_CHOP_L2,
7356 MENUID_CHEAT_CHOP_L3,
7357 MENUID_CHEAT_CHOP_L4,
7358 MENUID_CHEAT_INVULN,
7359 MENUID_CHEAT_NOCLIP,
7360 MENUID_CHEAT_IGNORESV,
7361 MENUID_CHEAT_GOFAST,
7362 };
7363
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 static NewMenu cheat_menu
7364 7259 {
7365
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Set &Cheat", onCheat },
7366
1/2
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
427 { MENUID_CHEAT_CHOP_L1 },
7367
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Re&fill", &refill_menu },
7368
1/2
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
427 { MENUID_CHEAT_CHOP_L2 },
7369
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7370
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Ma&x Bombs...", onMaxBombs },
7371
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Heart Containers...", onHeartC },
7372
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Magic Containers...", onMagicC },
7373
1/2
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
427 { MENUID_CHEAT_CHOP_L3 },
7374
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Hero Data...", onCheatConsole },
7375
1/2
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
427 { MENUID_CHEAT_CHOP_L4 },
7376
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7377
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Hero Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7378
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7379
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Kill All Enemies", onKillCheat },
7380
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Trigger &Secrets", onSecretsCheat },
7381
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Trigger Secrets Perm", onSecretsCheatPerm },
7382
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Show/Hide Layer", &show_menu },
7383
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "Toggle &Light", onLightSwitch },
7384
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Goto Location...", onGoTo },
7385 };
7386
7387 #if DEVLEVEL > 0
7388 int32_t devLogging();
7389 int32_t devDebug();
7390 int32_t devTimestmp();
7391 #if DEVLEVEL > 1
7392 int32_t setCheat();
7393 #endif //DEVLEVEL > 1
7394 enum
7395 {
7396 MENUID_DEV_LOGGING,
7397 MENUID_DEV_DEBUG,
7398 MENUID_DEV_TIMESTAMP,
7399 MENUID_DEV_SETCHEAT,
7400 };
7401 static NewMenu dev_menu
7402 {
7403 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7404 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7405 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7406 #if DEVLEVEL > 1
7407 {},
7408 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7409 #endif //DEVLEVEL > 1
7410 };
7411 int32_t devLogging()
7412 {
7413 dev_logging = !dev_logging;
7414 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7415 return D_O_K;
7416 }
7417 // int32_t devDebug()
7418 // {
7419 // dev_debug = !dev_debug;
7420 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7421 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7422 // return D_O_K;
7423 // }
7424 int32_t devTimestmp()
7425 {
7426 dev_timestmp = !dev_timestmp;
7427 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7428 return D_O_K;
7429 }
7430 #if DEVLEVEL > 1
7431 int32_t setCheat()
7432 {
7433 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7434 return D_O_K;
7435 }
7436 #endif //DEVLEVEL > 1
7437 #endif //DEVLEVEL > 0
7438
7439 enum
7440 {
7441 MENUID_PLAYER_CHEAT,
7442 };
7443
1/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
427 TopMenu the_player_menu
7444 2562 {
7445
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Game", &game_menu },
7446
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Settings", &settings_menu },
7447
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7448
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&Replay", &replay_menu },
7449
2/4
✓ Branch 0 taken 427 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 427 times.
✗ Branch 3 not taken.
427 { "&ZC", &misc_menu },
7450 #if DEVLEVEL > 0
7451 { "&Dev", &dev_menu },
7452 #endif
7453 };
7454
7455 int32_t onPauseInBackground()
7456 {
7457 if(jwin_alert3(
7458 "Toggle Pause In Background",
7459 "This action will change whether ZC Player pauses when the window loses focus.",
7460 "",
7461 "Proceed?",
7462 "&Yes",
7463 "&No",
7464 NULL,
7465 'y',
7466 'n',
7467 0,
7468 get_zc_font(font_lfont)) == 1)
7469 {
7470 pause_in_background = pause_in_background ? 0 : 1;
7471 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7472 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7473 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7474 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7475 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7476 }
7477 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7478 return D_O_K;
7479 }
7480
7481 int32_t onKeyboardEntry()
7482 {
7483 NameEntryMode=0;
7484 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7485 return D_O_K;
7486 }
7487
7488 int32_t onLetterGridEntry()
7489 {
7490 NameEntryMode=1;
7491 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7492 return D_O_K;
7493 }
7494
7495 int32_t onExtLetterGridEntry()
7496 {
7497 NameEntryMode=2;
7498 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7499 return D_O_K;
7500 }
7501
7502 static BITMAP* oldscreen;
7503 int32_t onFullscreenMenu()
7504 {
7505 PALETTE oldpal;
7506 get_palette(oldpal);
7507
7508 fullscreen = !fullscreen;
7509 all_toggle_fullscreen(fullscreen);
7510 zc_set_config("zeldadx","fullscreen",fullscreen);
7511
7512 zc_set_palette(oldpal);
7513 gui_mouse_focus=0;
7514 extern int32_t switch_type;
7515 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7516 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7517 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7518 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7519 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7520 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7521
7522 return D_O_K;
7523 }
7524
7525 323 void fix_menu()
7526 {
7527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 323 times.
323 if(!debug_enabled)
7528 323 settings_menu.chop_index = 13;
7529 323 }
7530
7531 int32_t onSetSnapshotFormat(SnapshotType format)
7532 {
7533 SnapshotFormat = format;
7534 zc_set_config("zeldadx", "snapshot_format", format);
7535 snapshot_format_menu.select_only_index(format);
7536 return D_O_K;
7537 }
7538
7539 int32_t onSetBottom8Pixels(int option)
7540 {
7541 ShowBottomPixels = option;
7542 zc_set_config("zeldadx", "bottom_8_px", option);
7543 bottom_8_pixels_menu.select_only_index(option);
7544
7545 int qr = qr_HIDE_BOTTOM_8_PIXELS;
7546 bool value = false;
7547 if (option == 0)
7548 value = get_bit(quest_rules, qr) != 0; // This is the original value, as set in the qst file (or via scripting).
7549 else if (option == 1)
7550 value = false;
7551 else if (option == 2)
7552 value = true;
7553 enqueue_qr_change(qr, value);
7554
7555 return D_O_K;
7556 }
7557
7558 3018 void updateShowBottomPixels()
7559 {
7560 // It's too tricky the allow modifying the screen height between opening and closing the
7561 // active subscreen.
7562
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2992 times.
3018 if (subscreen_open)
7563 26 return;
7564
7565
1/2
✓ Branch 0 taken 2992 times.
✗ Branch 1 not taken.
2992 if (!GameLoaded)
7566 show_bottom_8px = false;
7567 else
7568 2992 show_bottom_8px = !get_qr(qr_HIDE_BOTTOM_8_PIXELS);
7569
7570 2992 int target_bitmap_height = show_bottom_8px ? 232 : 224;
7571
2/2
✓ Branch 0 taken 2878 times.
✓ Branch 1 taken 114 times.
2992 if (framebuf->h != target_bitmap_height)
7572 {
7573 114 BITMAP* new_framebuf = create_bitmap_ex(8, 256, target_bitmap_height);
7574 114 clear_bitmap(new_framebuf);
7575 114 blit(framebuf, new_framebuf, 0, 0, 0, 0, new_framebuf->w, new_framebuf->h);
7576
7577 114 BITMAP* new_framebuf_active_subscreen = create_bitmap_ex(8, 256, target_bitmap_height);
7578 114 clear_bitmap(new_framebuf_active_subscreen);
7579
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 if (framebuf_no_passive_subscreen)
7580 114 blit(framebuf_no_passive_subscreen, new_framebuf_active_subscreen, 0, 0, 0, 0, new_framebuf_active_subscreen->w, new_framebuf_active_subscreen->h);
7581
7582 114 destroy_bitmap(framebuf);
7583 114 destroy_bitmap(framebuf_no_passive_subscreen);
7584 114 destroy_bitmap(script_menu_buf);
7585 114 destroy_bitmap(f6_menu_buf);
7586 114 destroy_bitmap(darkscr_bmp);
7587 114 destroy_bitmap(darkscr_bmp_trans);
7588
7589 114 framebuf = new_framebuf;
7590 114 framebuf_no_passive_subscreen = new_framebuf_active_subscreen;
7591 114 script_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7592 114 f6_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7593 114 darkscr_bmp = create_bitmap_ex(8, 256, target_bitmap_height);
7594 114 darkscr_bmp_trans = create_bitmap_ex(8, 256, target_bitmap_height);
7595
7596 114 rti_game.a4_bitmap = framebuf;
7597 114 rti_game.set_size(framebuf->w, framebuf->h);
7598 114 al_set_new_bitmap_flags(ALLEGRO_CONVERT_BITMAP);
7599 114 al_destroy_bitmap(rti_game.bitmap);
7600 114 rti_game.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7601 114 al_destroy_bitmap(rti_infolayer.bitmap);
7602 114 rti_infolayer.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7603 114 rti_infolayer.set_size(framebuf->w, framebuf->h);
7604 114 }
7605 3018 }
7606
7607 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7608 {
7609 PALETTE tmp;
7610
7611 for(int32_t i=0; i<256; i++)
7612 {
7613 tmp[i].r=r;
7614 tmp[i].g=g;
7615 tmp[i].b=b;
7616 }
7617
7618 fade_interpolate(src,tmp,dest,pos,from,to);
7619 }
7620
7621 59 void system_pal(bool force)
7622 {
7623
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
59 if(is_sys_pal && !force) return;
7624 59 is_sys_pal = true;
7625 59 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7626 59 hw_palette = &syspal;
7627 59 update_hw_pal = true;
7628 59 }
7629
7630 static uint32_t entered_sys_pal = 0;
7631 59 void enter_sys_pal()
7632 {
7633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if(is_sys_pal)
7634 {
7635 if(entered_sys_pal)
7636 ++entered_sys_pal;
7637 return;
7638 }
7639 59 sys_mouse();
7640 59 system_pal(true);
7641 59 ++entered_sys_pal;
7642 59 }
7643 59 void exit_sys_pal()
7644 {
7645
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if(entered_sys_pal)
7646 {
7647
1/2
✓ Branch 0 taken 59 times.
✗ Branch 1 not taken.
59 if(!--entered_sys_pal)
7648 {
7649 59 game_pal();
7650 59 game_mouse();
7651 59 }
7652 59 }
7653 59 }
7654
7655 void switch_out_callback()
7656 {
7657 if (pause_in_background && !MenuOpen)
7658 {
7659 System();
7660 }
7661 }
7662
7663 void switch_in_callback()
7664 {
7665 }
7666
7667 1204 void game_pal()
7668 {
7669 1204 is_sys_pal = false;
7670 1204 entered_sys_pal = 0;
7671 1204 hw_palette = &RAMpal;
7672 1204 update_hw_pal = true;
7673 1204 }
7674
7675 static char bar_str[] = "";
7676
7677 59 void music_pause()
7678 {
7679 //al_pause_duh(tmplayer);
7680 59 zcmusic_pause(zcmusic, ZCM_PAUSE);
7681
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if(zcmixer->oldtrack)
7682 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7683 59 zc_midi_pause();
7684 59 }
7685
7686 void music_resume()
7687 {
7688 //al_resume_duh(tmplayer);
7689 zcmusic_pause(zcmusic, ZCM_RESUME);
7690 if (zcmixer->oldtrack)
7691 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7692 zc_midi_resume();
7693 }
7694
7695 8354 void music_stop()
7696 {
7697 //al_stop_duh(tmplayer);
7698 //unload_duh(tmusic);
7699 //tmusic=NULL;
7700 //tmplayer=NULL;
7701 8354 zcmusic_stop(zcmusic);
7702 8354 zcmusic_unload_file(zcmusic);
7703
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8354 times.
8354 if (zcmixer->oldtrack)
7704 {
7705 zcmusic_stop(zcmixer->oldtrack);
7706 zcmusic_unload_file(zcmixer->oldtrack);
7707 }
7708 8354 zcmixer->newtrack = NULL;
7709 8354 zc_stop_midi();
7710 8354 currmidi=-1;
7711 8354 }
7712
7713 bool reload_fonts = false;
7714 void System()
7715 {
7716 mouse_down = gui_mouse_b();
7717 music_pause();
7718 pause_all_sfx();
7719 MenuOpen = true;
7720 enter_sys_pal();
7721 // FONT *oldfont=font;
7722 // font=tfont;
7723
7724 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7725 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7726
7727 #if DEVLEVEL > 1
7728 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7729 #endif
7730 game_menu.disable_uid(MENUID_GAME_LOADQUEST, get_unset_save_slot());
7731 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7732 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7733 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7734 clear_keybuf();
7735
7736 clear_bitmap(menu_bmp);
7737 oldscreen = screen;
7738 screen = menu_bmp;
7739
7740 the_player_menu.reset_state();
7741 the_player_menu.position(0, 0);
7742
7743 bool running = true;
7744 bool esc = key[KEY_ESC] || cMbtn();
7745 bool autopop = esc;
7746 do
7747 {
7748 if(reload_fonts)
7749 {
7750 init_custom_fonts();
7751 clear_bitmap(menu_bmp);
7752 broadcast_dialog_message(MSG_DRAW, 0);
7753 reload_fonts = false;
7754 }
7755 if(handle_close_btn_quit())
7756 break;
7757
7758 //update submenus
7759 {
7760 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7761 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7762 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7763 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7764 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7765 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7766 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7767 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7768
7769 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7770 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7771 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7772 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7773 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7774
7775 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7776 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7777 options_menu.disable_uid(MENUID_OPTIONS_SHOWBOTTOMPIXELS, replay_is_replaying());
7778
7779 name_entry_mode_menu.select_only_index(NameEntryMode);
7780
7781 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7782 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7783
7784 bool nocheat = (replay_is_replaying() || !Playing
7785 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7786 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7787 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7788 cheat_menu.chop_index.reset();
7789 if(cheat < 4)
7790 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7791 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7792 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, walk_through_walls);
7793 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7794 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7795
7796 show_menu.select_uid(MENUID_SHOW_L0, show_layers[0]);
7797 show_menu.select_uid(MENUID_SHOW_L1, show_layers[1]);
7798 show_menu.select_uid(MENUID_SHOW_L2, show_layers[2]);
7799 show_menu.select_uid(MENUID_SHOW_L3, show_layers[3]);
7800 show_menu.select_uid(MENUID_SHOW_L4, show_layers[4]);
7801 show_menu.select_uid(MENUID_SHOW_L5, show_layers[5]);
7802 show_menu.select_uid(MENUID_SHOW_L6, show_layers[6]);
7803 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7804 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7805 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7806 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7807 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7808 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7809 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7810 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7811
7812 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7813 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7814
7815 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7816 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7817
7818 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7819 #ifdef HAS_CURL
7820 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7821 #endif
7822 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7823 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7824 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7825
7826 snapshot_format_menu.select_only_index(SnapshotFormat);
7827 bottom_8_pixels_menu.select_only_index(ShowBottomPixels);
7828 }
7829
7830 if(debug_enabled)
7831 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7832
7833 if(autopop)
7834 clear_keybuf();
7835 the_player_menu.run(true);
7836 if(autopop)
7837 {
7838 the_player_menu.pop_sub(0, &the_player_menu);
7839 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7840 autopop = false;
7841 update_hw_screen();
7842 }
7843
7844 update_hw_screen();
7845
7846 auto mb = gui_mouse_b();
7847 if(XOR(mb, mouse_down))
7848 {
7849 if(!the_player_menu.has_mouse())
7850 if(mb)
7851 break;
7852 mouse_down = mb;
7853 }
7854
7855 if(input_idle(true) > after_time())
7856 // run Screeen Saver
7857 {
7858 // Screen saver enabled for now.
7859 clear_keybuf();
7860 Matrix(ss_speed, ss_density, 0);
7861 system_pal(true);
7862 sys_mouse();
7863 }
7864
7865 poll_keyboard();
7866 if(esc)
7867 {
7868 if(!key[KEY_ESC])
7869 esc = false;
7870 }
7871
7872 if(keypressed() && !CHECK_ALT) //System hotkeys
7873 {
7874 auto c = peekkey();
7875 bool eatkey = true;
7876 switch(c>>8)
7877 {
7878 //Spare keys used by the menu
7879 case KEY_UP:
7880 case KEY_DOWN:
7881 case KEY_LEFT:
7882 case KEY_RIGHT:
7883 eatkey = false;
7884 break;
7885 case KEY_F1:
7886 onThrottleFPS();
7887 break;
7888 case KEY_F2:
7889 onShowFPS();
7890 break;
7891 case KEY_F6:
7892 onTryQuitMenu();
7893 break;
7894 #ifndef ALLEGRO_MACOSX
7895 case KEY_F9:
7896 onReset();
7897 break;
7898 case KEY_F10:
7899 onExit();
7900 break;
7901 #else
7902 case KEY_F7:
7903 onReset();
7904 break;
7905 case KEY_F8:
7906 onExit();
7907 break;
7908 #endif
7909 case KEY_F12:
7910 onSnapshot();
7911 break;
7912 case KEY_TAB:
7913 onDebug();
7914 break;
7915 case KEY_ESC:
7916 if(!esc)
7917 running = false;
7918 break;
7919 }
7920 if(eatkey)
7921 readkey();
7922 }
7923 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7924 break;
7925 }
7926 while(running);
7927
7928 screen = oldscreen;
7929
7930 mouse_down=gui_mouse_b();
7931 MenuOpen = false;
7932 if(Quit)
7933 {
7934 kill_sfx();
7935 music_stop();
7936 update_hw_screen();
7937 }
7938 else
7939 {
7940 music_resume();
7941 resume_all_sfx();
7942
7943 if(rc)
7944 ringcolor(false);
7945 }
7946 exit_sys_pal();
7947
7948 eat_buttons();
7949
7950 rc=false;
7951 clear_keybuf();
7952
7953 zc_init_apply_cheat_delta();
7954 }
7955
7956 323 void fix_dialogs()
7957 {
7958 323 jwin_center_dialog(about_dlg);
7959 323 jwin_center_dialog(gamepad_dlg);
7960 323 jwin_center_dialog(credits_dlg);
7961 323 jwin_center_dialog(gamemode_dlg);
7962 323 jwin_center_dialog(getnum_dlg);
7963 323 jwin_center_dialog(goto_dlg);
7964 323 jwin_center_dialog(keyboard_control_dlg);
7965 323 jwin_center_dialog(midi_dlg);
7966 323 jwin_center_dialog(quest_dlg);
7967 323 jwin_center_dialog(scrsaver_dlg);
7968 323 jwin_center_dialog(sound_dlg);
7969 323 jwin_center_dialog(triforce_dlg);
7970 323 }
7971
7972 4339 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7973 {
7974
3/4
✓ Branch 0 taken 4339 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4317 times.
✓ Branch 3 taken 22 times.
4339 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7975 }
7976
7977 340 int32_t get_emusic_volume()
7978 {
7979 340 int32_t temp_volume = emusic_volume;
7980
3/4
✓ Branch 0 taken 340 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 294 times.
✓ Branch 3 taken 46 times.
340 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7981 46 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7982
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 340 times.
340 if (!zcmusic)
7983 340 return temp_volume;
7984 return (temp_volume * zcmusic->fadevolume) / 10000;
7985 340 }
7986
7987 int32_t get_zcmusicpos()
7988 {
7989 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7990 return debugtracething;
7991 return 0;
7992 }
7993
7994 void set_zcmusicpos(int32_t position)
7995 {
7996 zcmusic_set_curpos(zcmusic, position);
7997 }
7998
7999 void set_zcmusicspeed(int32_t speed)
8000 {
8001 zcmusic_set_speed(zcmusic, speed);
8002 }
8003
8004 int32_t get_zcmusiclen()
8005 {
8006 return zcmusic_get_length(zcmusic);
8007 }
8008
8009 3 void set_zcmusicloop(double start, double end)
8010 {
8011 3 zcmusic_set_loop(zcmusic, start, end);
8012 3 }
8013
8014 64179 void jukebox(int32_t index,int32_t loop)
8015 {
8016
1/2
✓ Branch 0 taken 64179 times.
✗ Branch 1 not taken.
64179 if (is_headless())
8017 64179 return;
8018
8019 music_stop();
8020
8021 if(index<0) index=MAXMIDIS-1;
8022
8023 if(index>=MAXMIDIS) index=0;
8024
8025 music_stop();
8026
8027 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8028 // stuck notes when a song stops. This fixes it.
8029 if(strcmp(midi_driver->name, "DIGMID")==0)
8030 zc_set_volume(0, 0);
8031
8032 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8033 zc_play_midi(tunes[index].data,loop);
8034
8035 if(tunes[index].start>0)
8036 zc_midi_seek(tunes[index].start);
8037
8038 midi_loop_start = tunes[index].loop_start;
8039 midi_loop_end = tunes[index].loop_end;
8040
8041 currmidi=index;
8042 master_volume(digi_volume, midi_volume);
8043 //midi_paused=false;
8044 64179 }
8045
8046 64179 void jukebox(int32_t index)
8047 {
8048
1/2
✓ Branch 0 taken 64179 times.
✗ Branch 1 not taken.
64179 if(index<0) index=MAXMIDIS-1;
8049
8050
1/2
✓ Branch 0 taken 64179 times.
✗ Branch 1 not taken.
64179 if(index>=MAXMIDIS) index=0;
8051
8052 // do nothing if it's already playing
8053
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64179 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64179 if(index==currmidi && midi_pos>=0)
8054 {
8055 return;
8056 }
8057
8058 64179 jukebox(index,tunes[index].loop);
8059 64179 }
8060
8061 110 void play_DmapMusic()
8062 {
8063
1/2
✓ Branch 0 taken 110 times.
✗ Branch 1 not taken.
110 if (is_headless())
8064 110 return;
8065
8066 static char tfile[2048];
8067 static int32_t ttrack=0;
8068 bool domidi=false;
8069
8070 int32_t fadeoutframes = 0;
8071 if (zcmusic != NULL)
8072 fadeoutframes = zcmusic->fadeoutframes;
8073
8074 if(DMaps[cur_dmap].tmusic[0]!=0)
8075 {
8076 if(zcmusic==NULL ||
8077 strcmp(zcmusic->filename,DMaps[cur_dmap].tmusic)!=0 ||
8078 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[cur_dmap].tmusictrack))
8079 {
8080 if (DMaps[cur_dmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8081 {
8082 if (play_enh_music_crossfade(DMaps[cur_dmap].tmusic, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes))
8083 {
8084 if (zcmusic != NULL)
8085 {
8086 zcmusic->fadeoutframes = DMaps[cur_dmap].tmusic_xfade_out;
8087 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8088 }
8089 }
8090 }
8091 else
8092 {
8093 if (zcmusic != NULL)
8094 {
8095 zcmusic_stop(zcmusic);
8096 zcmusic_unload_file(zcmusic);
8097 zcmusic = NULL;
8098 zcmixer->newtrack = NULL;
8099 }
8100
8101 zcmusic = zcmusic_load_for_quest(DMaps[cur_dmap].tmusic, qstpath).first;
8102 zcmixer->newtrack = zcmusic;
8103
8104 if (zcmusic != NULL)
8105 {
8106 zc_stop_midi();
8107 strcpy(tfile, DMaps[cur_dmap].tmusic);
8108 zcmusic_play(zcmusic, emusic_volume);
8109 int32_t temptracks = 0;
8110 temptracks = zcmusic_get_tracks(zcmusic);
8111 temptracks = (temptracks < 2) ? 1 : temptracks;
8112 ttrack = vbound(DMaps[cur_dmap].tmusictrack, 0, temptracks - 1);
8113 zcmusic_change_track(zcmusic, ttrack);
8114 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8115 }
8116 else
8117 {
8118 tfile[0] = 0;
8119 domidi = true;
8120 }
8121 }
8122 }
8123 }
8124 else
8125 {
8126 if (DMaps[cur_dmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[cur_dmap].tmusic) != 0)
8127 {
8128 play_enh_music_crossfade(NULL, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes);
8129 }
8130 else
8131 {
8132 domidi = true;
8133 }
8134 }
8135
8136 if(domidi)
8137 {
8138 int32_t m=DMaps[cur_dmap].midi;
8139
8140 switch(m)
8141 {
8142 case 1:
8143 jukebox(ZC_MIDI_OVERWORLD);
8144 break;
8145
8146 case 2:
8147 jukebox(ZC_MIDI_DUNGEON);
8148 break;
8149
8150 case 3:
8151 jukebox(ZC_MIDI_LEVEL9);
8152 break;
8153
8154 default:
8155 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8156 jukebox(m+MIDIOFFSET_DMAP);
8157 else
8158 music_stop();
8159 }
8160 }
8161 110 }
8162
8163 37444 void playLevelMusic()
8164 {
8165
1/2
✓ Branch 0 taken 37444 times.
✗ Branch 1 not taken.
37444 if (is_headless())
8166 37444 return;
8167
8168 int32_t m=hero_scr->screen_midi;
8169
8170 switch(m)
8171 {
8172 case -2:
8173 music_stop();
8174 break;
8175
8176 case -1:
8177 play_DmapMusic();
8178 break;
8179
8180 case 1:
8181 jukebox(ZC_MIDI_OVERWORLD);
8182 break;
8183
8184 case 2:
8185 jukebox(ZC_MIDI_DUNGEON);
8186 break;
8187
8188 case 3:
8189 jukebox(ZC_MIDI_LEVEL9);
8190 break;
8191
8192 default:
8193 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8194 jukebox(m+MIDIOFFSET_MAPSCR);
8195 else
8196 music_stop();
8197 }
8198 37444 }
8199
8200 4339 void master_volume(int32_t dv,int32_t mv)
8201 {
8202
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2331 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 364 times.
✓ Branch 4 taken 2331 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 364 times.
4339 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8203
8204
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2335 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 335 times.
✓ Branch 4 taken 2335 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 335 times.
4339 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8205
8206
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4339 times.
✓ Branch 2 taken 4339 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4339 times.
4339 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8207 4339 int32_t temp_vol = midi_volume;
8208
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 323 times.
4339 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8209 323 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8210 4339 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8211 4339 }
8212
8213 // array of voices, one for each sfx sample in the data file
8214 // 0+ = voice #
8215 // -1 = voice not allocated
8216 323 void Z_init_sound()
8217 {
8218
2/2
✓ Branch 0 taken 82688 times.
✓ Branch 1 taken 323 times.
83011 for(int32_t i=0; i<WAV_COUNT; i++)
8219 82688 sfx_voice[i]=-1;
8220
8221 323 const char* midis[ZC_MIDI_COUNT] = {
8222 "assets/dungeon.mid",
8223 "assets/ending.mid",
8224 "assets/gameover.mid",
8225 "assets/level9.mid",
8226 "assets/overworld.mid",
8227 "assets/title.mid",
8228 "assets/triforce.mid",
8229 };
8230
2/2
✓ Branch 0 taken 2261 times.
✓ Branch 1 taken 323 times.
2584 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8231 {
8232 2261 tunes[i].data = load_midi(midis[i]);
8233
1/2
✓ Branch 0 taken 2261 times.
✗ Branch 1 not taken.
2261 if (!tunes[i].data)
8234 Z_error_fatal("Missing required file %s\n", midis[i]);
8235 2261 }
8236
8237
2/2
✓ Branch 0 taken 81396 times.
✓ Branch 1 taken 323 times.
81719 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8238 81396 tunes[ZC_MIDI_COUNT+j].data=NULL;
8239
8240 323 master_volume(digi_volume,midi_volume);
8241 323 }
8242
8243 // returns number of voices currently allocated
8244 int32_t sfx_count()
8245 {
8246 int32_t c=0;
8247
8248 for(int32_t i=0; i<WAV_COUNT; i++)
8249 if(sfx_voice[i]!=-1)
8250 ++c;
8251
8252 return c;
8253 }
8254
8255 // clean up finished samples
8256 19010727 void sfx_cleanup()
8257 {
8258
2/2
✓ Branch 0 taken 4866746112 times.
✓ Branch 1 taken 19010727 times.
4885756839 for(int32_t i=0; i<WAV_COUNT; i++)
8259
3/4
✓ Branch 0 taken 1310532 times.
✓ Branch 1 taken 4865435580 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1310532 times.
4868056644 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8260 {
8261 1310532 deallocate_voice(sfx_voice[i]);
8262 1310532 sfx_voice[i]=-1;
8263 1310532 }
8264 19010727 }
8265
8266 1310712 SAMPLE* sfx_get_sample(int32_t index)
8267 {
8268 // check index
8269
2/4
✓ Branch 0 taken 1310712 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1310712 times.
1310712 if (index<=0 || index>=WAV_COUNT)
8270 return nullptr;
8271
8272
2/2
✓ Branch 0 taken 446247 times.
✓ Branch 1 taken 864465 times.
1310712 if (sfxdat)
8273 {
8274
1/2
✓ Branch 0 taken 446247 times.
✗ Branch 1 not taken.
446247 if (index<Z35)
8275 {
8276 446247 return (SAMPLE*)sfxdata[index].dat;
8277 }
8278 else
8279 {
8280 return (SAMPLE*)sfxdata[Z35].dat;
8281 }
8282 }
8283 else
8284 {
8285 864465 return &customsfxdata[index];
8286 }
8287
8288 return nullptr;
8289 1310712 }
8290
8291 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8292 // if a voice is already allocated (and/or playing), then it just returns true
8293 // Returns true: voice is allocated
8294 // false: unsuccessful
8295 2065236 bool sfx_init(int32_t index)
8296 {
8297 // check index
8298
3/4
✓ Branch 0 taken 1468495 times.
✓ Branch 1 taken 596741 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1468495 times.
2065236 if(index<=0 || index>=WAV_COUNT)
8299 596741 return false;
8300
8301
2/2
✓ Branch 0 taken 157848 times.
✓ Branch 1 taken 1310647 times.
1468495 if (sfx_voice[index] == -1)
8302 {
8303 1310647 SAMPLE* sample = sfx_get_sample(index);
8304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1310647 times.
1310647 if (!sample)
8305 return false;
8306
8307 1310647 sfx_voice[index] = allocate_voice(sample);
8308 1310647 }
8309
8310 1468495 return sfx_voice[index] != -1;
8311 2065236 }
8312
8313 int32_t sfx_get_default_freq(int32_t index)
8314 {
8315 if (sfxdat)
8316 {
8317 if (index < Z35)
8318 {
8319 return ((SAMPLE*)sfxdata[index].dat)->freq;
8320 }
8321 else
8322 {
8323 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8324 }
8325 }
8326 else
8327 {
8328 return customsfxdata[index].freq;
8329 }
8330 }
8331
8332 int32_t sfx_get_length(int32_t index)
8333 {
8334 if (sfxdat)
8335 {
8336 if (index < Z35)
8337 {
8338 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8339 }
8340 else
8341 {
8342 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8343 }
8344 }
8345 else
8346 {
8347 return int32_t(customsfxdata[index].len);
8348 }
8349 }
8350
8351 // plays an sfx sample
8352 2065236 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8353 {
8354
2/2
✓ Branch 0 taken 1468495 times.
✓ Branch 1 taken 596741 times.
2065236 if(!sfx_init(index))
8355 596741 return;
8356
1/2
✓ Branch 0 taken 1468495 times.
✗ Branch 1 not taken.
1468495 if (!is_headless())
8357 {
8358 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8359 voice_set_pan(sfx_voice[index], pan);
8360
8361 // Only used by ZScript currently
8362 if (freq <= -1)
8363 {
8364 freq = sfx_get_default_freq(index);
8365 }
8366 voice_set_frequency(sfx_voice[index], freq);
8367
8368 // Only used by ZScript currently
8369 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8370 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8371 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8372 voice_set_volume(sfx_voice[index], temp_volume);
8373
8374 int32_t pos = voice_get_position(sfx_voice[index]);
8375
8376 if (restart) voice_set_position(sfx_voice[index], 0);
8377
8378 if (pos <= 0)
8379 voice_start(sfx_voice[index]);
8380 }
8381
8382
3/4
✓ Branch 0 taken 925993 times.
✓ Branch 1 taken 542502 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 925993 times.
1468495 if (restart && replay_is_debug())
8383 {
8384 // TODO(replays): get rid of this bandaid next time replays are mass-updated.
8385 925993 const char* sfx_name = sfx_string[index];
8386
2/2
✓ Branch 0 taken 914193 times.
✓ Branch 1 taken 11800 times.
925993 if (strcmp(sfx_name, "Hero is hit") == 0)
8387 11800 sfx_name = "Player is hit";
8388
2/2
✓ Branch 0 taken 914066 times.
✓ Branch 1 taken 127 times.
914193 else if (strcmp(sfx_name, "Hero dies") == 0)
8389 127 sfx_name = "Player dies";
8390
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 925993 times.
925993 replay_step_comment(fmt::format("sfx {}", sfx_name));
8391 925993 }
8392 2065236 }
8393
8394 // true if sfx is allocated
8395 234209 bool sfx_allocated(int32_t index)
8396 {
8397
3/4
✓ Branch 0 taken 33547 times.
✓ Branch 1 taken 200662 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33547 times.
234209 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8398 }
8399
8400 // start it (in loop mode) if it's not already playing,
8401 // otherwise adjust it to play in loop mode -DD
8402 125902 void cont_sfx(int32_t index)
8403 {
8404
1/2
✓ Branch 0 taken 125902 times.
✗ Branch 1 not taken.
125902 if (is_headless())
8405 125902 return;
8406
8407 if(!sfx_init(index))
8408 {
8409 return;
8410 }
8411
8412 if(voice_get_position(sfx_voice[index])<=0)
8413 {
8414 voice_set_position(sfx_voice[index],0);
8415 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8416 voice_set_volume(sfx_voice[index], sfx_volume);
8417 voice_start(sfx_voice[index]);
8418 }
8419 else
8420 {
8421 adjust_sfx(index, 128, true);
8422 }
8423 125902 }
8424
8425 // adjust parameters while playing
8426 5377 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8427 {
8428
4/6
✓ Branch 0 taken 4828 times.
✓ Branch 1 taken 549 times.
✓ Branch 2 taken 4828 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4828 times.
5377 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8429 5377 return;
8430
8431 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8432 voice_set_pan(sfx_voice[index],pan);
8433 5377 }
8434
8435 // pauses a voice
8436 3364 void pause_sfx(int32_t index)
8437 {
8438
3/6
✓ Branch 0 taken 3364 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3364 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3364 times.
3364 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8439 voice_stop(sfx_voice[index]);
8440 3364 }
8441
8442 // resumes a voice
8443 1427 void resume_sfx(int32_t index)
8444 {
8445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1427 times.
1427 if (is_headless())
8446 1427 return;
8447
8448 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8449 voice_start(sfx_voice[index]);
8450 1427 }
8451
8452 // pauses all active voices
8453 1129 void pause_all_sfx()
8454 {
8455
2/2
✓ Branch 0 taken 289024 times.
✓ Branch 1 taken 1129 times.
290153 for(int32_t i=0; i<WAV_COUNT; i++)
8456
2/2
✓ Branch 0 taken 289022 times.
✓ Branch 1 taken 2 times.
289026 if(sfx_voice[i]!=-1)
8457 2 voice_stop(sfx_voice[i]);
8458 1129 }
8459
8460 // resumes all paused voices
8461 1070 void resume_all_sfx()
8462 {
8463
2/2
✓ Branch 0 taken 273920 times.
✓ Branch 1 taken 1070 times.
274990 for(int32_t i=0; i<WAV_COUNT; i++)
8464
1/2
✓ Branch 0 taken 273920 times.
✗ Branch 1 not taken.
273920 if(sfx_voice[i]!=-1)
8465 voice_start(sfx_voice[i]);
8466 1070 }
8467
8468 // stops an sfx and deallocates the voice
8469 15160910 void stop_sfx(int32_t index)
8470 {
8471
3/4
✓ Branch 0 taken 14907157 times.
✓ Branch 1 taken 253753 times.
✓ Branch 2 taken 14907157 times.
✗ Branch 3 not taken.
15160910 if(index<=0 || index>=WAV_COUNT)
8472 253753 return;
8473
8474
2/2
✓ Branch 0 taken 57 times.
✓ Branch 1 taken 14907100 times.
14907157 if(sfx_voice[index]!=-1)
8475 {
8476 57 deallocate_voice(sfx_voice[index]);
8477 57 sfx_voice[index]=-1;
8478 57 }
8479 15160910 }
8480
8481 // Stops SFX played by Hero's item of the given family
8482 163371 void stop_item_sfx(int32_t family)
8483 {
8484 163371 int32_t id=current_item_id(family);
8485
8486
2/2
✓ Branch 0 taken 162269 times.
✓ Branch 1 taken 1102 times.
163371 if(id<0)
8487 162269 return;
8488
8489 1102 stop_sfx(itemsbuf[id].usesound);
8490 163371 }
8491
8492 9760 void kill_sfx()
8493 {
8494
2/2
✓ Branch 0 taken 2498560 times.
✓ Branch 1 taken 9760 times.
2508320 for(int32_t i=0; i<WAV_COUNT; i++)
8495
2/2
✓ Branch 0 taken 2498502 times.
✓ Branch 1 taken 58 times.
2498618 if(sfx_voice[i]!=-1)
8496 {
8497 58 deallocate_voice(sfx_voice[i]);
8498 58 sfx_voice[i]=-1;
8499 58 }
8500 9760 }
8501
8502 // TODO: when far out of bounds, sounds should dampen. currently we only pan.
8503 1256758 int32_t pan(int32_t x)
8504 {
8505
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1256758 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1256758 switch(pan_style)
8506 {
8507 // MONO
8508 case 0:
8509 return 128;
8510
8511 // 1/2
8512 case 1:
8513 1256758 x -= viewport.x;
8514 1256758 return vbound((x>>1)+68,0,255);
8515
8516 // 3/4
8517 case 2:
8518 x -= viewport.x;
8519 return vbound(((x*3)>>2)+36,0,255);
8520
8521 // FULL
8522 case 3:
8523 default:
8524 x -= viewport.x;
8525 return vbound(x,0,255);
8526 }
8527 1256758 }
8528
8529 52063298 bool joybtn(int32_t b)
8530 {
8531
1/2
✓ Branch 0 taken 52063298 times.
✗ Branch 1 not taken.
52063298 if(b == 0)
8532 return false;
8533
1/2
✓ Branch 0 taken 52063298 times.
✗ Branch 1 not taken.
52063298 if (b-1 >= joy[joystick_index].num_buttons)
8534 52063298 return false;
8535
8536 return joy[joystick_index].button[b-1].b !=0;
8537 52063298 }
8538
8539 bool joystick(int32_t s)
8540 {
8541 if(s < 0)
8542 return false;
8543 if (s >= joy[joystick_index].num_sticks)
8544 return false;
8545
8546 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8547 {
8548 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8549 return true;
8550 }
8551 return false;
8552 }
8553
8554 const char* joybtn_name(int32_t b)
8555 {
8556 if (b <= 0 || b > joy[joystick_index].num_buttons)
8557 return "";
8558
8559 return joy[joystick_index].button[b-1].name;
8560 }
8561
8562 const char* joystick_name(int32_t s)
8563 {
8564 if (s < 0 || s >= joy[joystick_index].num_sticks)
8565 return "";
8566
8567 return joy[joystick_index].stick[s].name;
8568 }
8569
8570 int32_t button_pressed()
8571 {
8572 if (joystick_index >= MAX_JOYSTICKS)
8573 return 0;
8574
8575 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8576 {
8577 if(joybtn(i))
8578 return i;
8579 }
8580
8581 return 0;
8582 }
8583
8584 int32_t next_press_key();
8585
8586 int32_t next_joy_input(bool buttons)
8587 {
8588 clear_keybuf();
8589
8590 //first, we need to wait until they're pressing no buttons
8591 for(;;)
8592 {
8593 if(keypressed())
8594 {
8595 switch(readkey()>>8)
8596 {
8597 case KEY_ESC:
8598 return -1;
8599
8600 case KEY_SPACE:
8601 return 0;
8602 }
8603 }
8604
8605 poll_joystick();
8606 bool done = true;
8607
8608 if (buttons)
8609 {
8610 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8611 {
8612 if(joybtn(i)) done = false;
8613 }
8614 }
8615 else
8616 {
8617 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8618 {
8619 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8620 return -2;
8621 }
8622 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8623 {
8624 if(joystick(i)) done = false;
8625 }
8626 }
8627
8628 if(done) break;
8629 rest(1);
8630 }
8631
8632 //now, we need to wait for them to press any button
8633 for(;;)
8634 {
8635 if(keypressed())
8636 {
8637 switch(readkey()>>8)
8638 {
8639 case KEY_ESC:
8640 return -1;
8641
8642 case KEY_SPACE:
8643 return 0;
8644 }
8645 }
8646
8647 poll_joystick();
8648
8649 if (buttons)
8650 {
8651 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8652 {
8653 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8654 return -2;
8655 }
8656 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8657 {
8658 if(joybtn(i))
8659 return i;
8660 }
8661 }
8662 else
8663 {
8664 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8665 {
8666 if(joystick(i))
8667 return i;
8668 }
8669 }
8670 rest(1);
8671 }
8672 }
8673
8674 12806099 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8675 {
8676
2/2
✓ Branch 0 taken 12722418 times.
✓ Branch 1 taken 83681 times.
12806099 bool ret = btn && !flag;
8677 12806099 flag = rawbtn;
8678
8679 12806099 return ret;
8680 }
8681 387812858 static bool rButton(bool &btn, bool &flag)
8682 {
8683
2/2
✓ Branch 0 taken 373295955 times.
✓ Branch 1 taken 14516903 times.
387812858 bool ret = btn && !flag;
8684 387812858 flag = btn;
8685
8686 387812858 return ret;
8687 }
8688 4658044 static bool rButtonPeek(bool btn, bool flag)
8689 {
8690
2/2
✓ Branch 0 taken 4308953 times.
✓ Branch 1 taken 349091 times.
4658044 if(!btn)
8691 {
8692 4308953 return false;
8693 }
8694
2/2
✓ Branch 0 taken 33877 times.
✓ Branch 1 taken 315214 times.
349091 else if(!flag)
8695 {
8696 33877 return true;
8697 }
8698
8699 315214 return false;
8700 4658044 }
8701
8702 // Updated only by keyboard/gamepad.
8703 // If in replay mode, this is set directly by the replay system.
8704 // This should never be read from directly - use control_state instead.
8705 bool raw_control_state[ZC_CONTROL_STATES];
8706
8707 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8708 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8709 // lasts until the next call to load_control_state.
8710 bool control_state[ZC_CONTROL_STATES];
8711 bool disable_control[ZC_CONTROL_STATES];
8712 bool drunk_toggle_state[11];
8713 bool disabledKeys[127];
8714 bool KeyInput[127];
8715 bool KeyPress[127];
8716
8717 bool key_current_frame[127];
8718 bool key_previous_frame[127];
8719
8720 static bool key_system[127];
8721 static bool key_system_previous[127];
8722 static bool key_system_press[127];
8723
8724 bool button_press[ZC_CONTROL_STATES];
8725 bool button_hold[ZC_CONTROL_STATES];
8726
8727 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8728 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8729 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8730 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8731 #define STICK_PRECISION 56 //define your own sensitivity
8732
8733 16269090 void load_control_state()
8734 {
8735 16269090 load_control_called_this_frame = true;
8736
8737
2/2
✓ Branch 0 taken 13066028 times.
✓ Branch 1 taken 3203062 times.
16269090 if (replay_version_check(8, 11))
8738 {
8739
2/2
✓ Branch 0 taken 57655116 times.
✓ Branch 1 taken 3203062 times.
60858178 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8740 57655116 down_control_states[i] = raw_control_state[i];
8741 3203062 }
8742
8743
2/2
✓ Branch 0 taken 16269069 times.
✓ Branch 1 taken 21 times.
16269090 if (!replay_is_replaying())
8744 {
8745
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8746
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8747
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8748
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8754
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8757
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8759
8760
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8761 {
8762 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8763 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8764 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8765 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8766 }
8767 else
8768 {
8769 21 raw_control_state[14] = false;
8770 21 raw_control_state[15] = false;
8771 21 raw_control_state[16] = false;
8772 21 raw_control_state[17] = false;
8773 }
8774 21 }
8775
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 16269085 times.
16269090 if (replay_is_active())
8776 {
8777
2/2
✓ Branch 0 taken 1211700 times.
✓ Branch 1 taken 15057385 times.
16269085 if (replay_get_version() < 3)
8778 1211700 replay_poll();
8779
4/4
✓ Branch 0 taken 15057364 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 13295989 times.
✓ Branch 3 taken 1761375 times.
15057385 else if (replay_is_replaying() && replay_get_version() < 6)
8780 1761375 replay_peek_input();
8781
4/4
✓ Branch 0 taken 13295989 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 10092927 times.
✓ Branch 3 taken 3203062 times.
13296010 else if (replay_is_replaying() && replay_version_check(8, 11))
8782 3203062 replay_peek_input();
8783
2/2
✓ Branch 0 taken 14929143 times.
✓ Branch 1 taken 1339942 times.
16269085 if (replay_get_version() == 8)
8784 1339942 update_keys();
8785 16269085 }
8786
8787 // Some test replay files were made before a serious input bug was fixed, so instead
8788 // of re-doing them or tossing them out, just check for that zplay version.
8789
3/4
✓ Branch 0 taken 16269080 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 16147180 times.
16269090 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8790
2/2
✓ Branch 0 taken 292843440 times.
✓ Branch 1 taken 16269080 times.
309112520 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8791 {
8792 292843440 control_state[i] = raw_control_state[i];
8793
4/4
✓ Branch 0 taken 53024004 times.
✓ Branch 1 taken 239819436 times.
✓ Branch 2 taken 2611994 times.
✓ Branch 3 taken 50412010 times.
292843440 if (botched_input && !control_state[i])
8794 50412010 down_control_states[i] = false;
8795 292843440 }
8796 16269080 bool did_bad_cutscene_btn = false;
8797
2/2
✓ Branch 0 taken 16269080 times.
✓ Branch 1 taken 292843440 times.
309112520 for(int q = 0; q < 18; ++q)
8798
4/4
✓ Branch 0 taken 13941524 times.
✓ Branch 1 taken 278901916 times.
✓ Branch 2 taken 13939813 times.
✓ Branch 3 taken 1711 times.
292845151 if(control_state[q] && !active_cutscene.can_button(q))
8799 {
8800 1711 control_state[q] = false;
8801 1711 did_bad_cutscene_btn = true;
8802 1711 }
8803
2/2
✓ Branch 0 taken 16267813 times.
✓ Branch 1 taken 1267 times.
16269080 if(did_bad_cutscene_btn)
8804 1267 active_cutscene.error();
8805
8806 16269080 button_press[0]=rButton(control_state[0],button_hold[0]);
8807 16269080 button_press[1]=rButton(control_state[1],button_hold[1]);
8808 16269080 button_press[2]=rButton(control_state[2],button_hold[2]);
8809 16269080 button_press[3]=rButton(control_state[3],button_hold[3]);
8810 16269080 button_press[4]=rButton(control_state[4],button_hold[4]);
8811 16269080 button_press[5]=rButton(control_state[5],button_hold[5]);
8812 16269080 button_press[6]=rButton(control_state[6],button_hold[6]);
8813 16269080 button_press[7]=rButton(control_state[7],button_hold[7]);
8814 16269080 button_press[8]=rButton(control_state[8],button_hold[8]);
8815 16269080 button_press[9]=rButton(control_state[9],button_hold[9]);
8816 16269080 button_press[10]=rButton(control_state[10],button_hold[10]);
8817 16269080 button_press[11]=rButton(control_state[11],button_hold[11]);
8818 16269080 button_press[12]=rButton(control_state[12],button_hold[12]);
8819 16269080 button_press[13]=rButton(control_state[13],button_hold[13]);
8820 16269080 button_press[14]=rButton(control_state[14],button_hold[14]);
8821 16269080 button_press[15]=rButton(control_state[15],button_hold[15]);
8822 16269080 button_press[16]=rButton(control_state[16],button_hold[16]);
8823 16269080 button_press[17]=rButton(control_state[17],button_hold[17]);
8824 16269080 }
8825
8826 // Returns true if any game key is pressed. This is needed because keypressed()
8827 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8828 81383241 bool zc_key_pressed()
8829 //may also need to use zc_getrawkey
8830 {
8831
7/10
✓ Branch 0 taken 65669909 times.
✓ Branch 1 taken 15713332 times.
✓ Branch 2 taken 15713332 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15713332 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12839449 times.
✓ Branch 7 taken 12839449 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5123906 times.
86507147 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8832
4/6
✓ Branch 0 taken 12839449 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12839449 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9756002 times.
✓ Branch 5 taken 9756002 times.
12839449 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8833
4/6
✓ Branch 0 taken 9756002 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9756002 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6454539 times.
✓ Branch 5 taken 6454539 times.
9756002 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8834
4/6
✓ Branch 0 taken 6454539 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6454539 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5543150 times.
✓ Branch 5 taken 5543150 times.
6454539 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8835
1/2
✓ Branch 0 taken 5543150 times.
✗ Branch 1 not taken.
5543150 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8836
3/4
✓ Branch 0 taken 5349452 times.
✓ Branch 1 taken 193698 times.
✓ Branch 2 taken 5349452 times.
✗ Branch 3 not taken.
5543150 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8837
3/4
✓ Branch 0 taken 5201299 times.
✓ Branch 1 taken 148153 times.
✓ Branch 2 taken 5201299 times.
✗ Branch 3 not taken.
5349452 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8838
3/4
✓ Branch 0 taken 5177796 times.
✓ Branch 1 taken 23503 times.
✓ Branch 2 taken 5177796 times.
✗ Branch 3 not taken.
5201299 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8839
3/4
✓ Branch 0 taken 5150623 times.
✓ Branch 1 taken 27173 times.
✓ Branch 2 taken 5150623 times.
✗ Branch 3 not taken.
5177796 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8840
3/4
✓ Branch 0 taken 5143068 times.
✓ Branch 1 taken 7555 times.
✓ Branch 2 taken 5143068 times.
✗ Branch 3 not taken.
5150623 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8841
3/4
✓ Branch 0 taken 5125829 times.
✓ Branch 1 taken 17239 times.
✓ Branch 2 taken 5125829 times.
✗ Branch 3 not taken.
5143068 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8842
3/4
✓ Branch 0 taken 5124000 times.
✓ Branch 1 taken 1829 times.
✓ Branch 2 taken 5124000 times.
✗ Branch 3 not taken.
5125829 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8843
3/4
✓ Branch 0 taken 5123965 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 5123965 times.
✗ Branch 3 not taken.
5124000 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8844
2/2
✓ Branch 0 taken 5123906 times.
✓ Branch 1 taken 59 times.
5123965 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8845 145445615 return true;
8846
8847 5123906 return false;
8848 19229703 }
8849
8850 311902181 bool getInput(int32_t btn, int input_flags)
8851 {
8852
3/4
✓ Branch 0 taken 277998546 times.
✓ Branch 1 taken 33903635 times.
✓ Branch 2 taken 277998546 times.
✗ Branch 3 not taken.
311902181 if((input_flags & INPUT_HERO_ACTION) && Hero.no_control())
8853 return false;
8854
8855 311902181 bool press = input_flags & INPUT_PRESS;
8856 311902181 bool drunk = input_flags & INPUT_DRUNK;
8857 311902181 bool ignoreDisable = input_flags & INPUT_IGNORE_DISABLE;
8858 311902181 bool eatEntirely = input_flags & INPUT_EAT_ENTIRELY;
8859 311902181 bool peek = input_flags & INPUT_PEEK;
8860
8861 311902181 bool ret = false, drunkstate = false, rawret = false;;
8862 311902181 bool* flag = &down_control_states[btn];
8863
2/7
✓ Branch 0 taken 292653209 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 19248972 times.
311902181 switch(btn)
8864 {
8865 case btnF12:
8866 ret = zc_getkey(KEY_F12, ignoreDisable);
8867 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8868 eatEntirely = false;
8869 break;
8870 case btnF11:
8871 ret = zc_getkey(KEY_F11, ignoreDisable);
8872 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8873 eatEntirely = false;
8874 break;
8875 case btnF5:
8876 ret = zc_getkey(KEY_F5, ignoreDisable);
8877 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8878 eatEntirely = false;
8879 break;
8880 case btnQ:
8881 ret = zc_getkey(KEY_Q, ignoreDisable);
8882 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8883 eatEntirely = false;
8884 break;
8885 case btnI:
8886 ret = zc_getkey(KEY_I, ignoreDisable);
8887 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8888 eatEntirely = false;
8889 break;
8890 case btnM:
8891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19248972 times.
19248972 if(FFCore.kb_typing_mode) return false;
8892 19248972 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8893 19248972 eatEntirely = false;
8894 19248972 break;
8895 default: //control_state[] index
8896
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 292653209 times.
292653209 if(FFCore.kb_typing_mode) return false;
8897
6/6
✓ Branch 0 taken 291255979 times.
✓ Branch 1 taken 1397230 times.
✓ Branch 2 taken 29315404 times.
✓ Branch 3 taken 261940575 times.
✓ Branch 4 taken 29312431 times.
✓ Branch 5 taken 2973 times.
292653209 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8898
2/2
✓ Branch 0 taken 17525518 times.
✓ Branch 1 taken 275124718 times.
292650236 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8899
4/4
✓ Branch 0 taken 259655930 times.
✓ Branch 1 taken 32997279 times.
✓ Branch 2 taken 7283 times.
✓ Branch 3 taken 32989996 times.
325650488 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8900 292653209 rawret = raw_control_state[btn];
8901 292653209 }
8902
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 311902181 times.
311902181 assert(flag);
8903
2/2
✓ Branch 0 taken 199468620 times.
✓ Branch 1 taken 112433561 times.
311902181 if(press)
8904 {
8905
2/2
✓ Branch 0 taken 4658044 times.
✓ Branch 1 taken 107775517 times.
112433561 if(peek)
8906 4658044 ret = rButtonPeek(ret, *flag);
8907
2/2
✓ Branch 0 taken 94969418 times.
✓ Branch 1 taken 12806099 times.
107775517 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8908 12806099 else ret = rButton(ret, *flag, rawret);
8909 112433561 }
8910
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 311902181 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
311902181 if(eatEntirely && ret) control_state[btn] = false;
8911
4/4
✓ Branch 0 taken 232456853 times.
✓ Branch 1 taken 79445328 times.
✓ Branch 2 taken 232456772 times.
✓ Branch 3 taken 81 times.
311902181 if(drunk && drunkstate) ret = !ret;
8912 311902181 return ret;
8913 311902181 }
8914
8915 15562981 byte getIntBtnInput(byte intbtn, int input_flags)
8916 {
8917 15562981 byte ret = 0;
8918
2/2
✓ Branch 0 taken 11119281 times.
✓ Branch 1 taken 4443700 times.
15562981 if(intbtn & INT_BTN_A) ret |= getInput(btnA, input_flags) ? INT_BTN_A : 0;
8919
2/2
✓ Branch 0 taken 15346113 times.
✓ Branch 1 taken 216868 times.
15562981 if(intbtn & INT_BTN_B) ret |= getInput(btnB, input_flags) ? INT_BTN_B : 0;
8920
2/2
✓ Branch 0 taken 15347431 times.
✓ Branch 1 taken 215550 times.
15562981 if(intbtn & INT_BTN_L) ret |= getInput(btnL, input_flags) ? INT_BTN_L : 0;
8921
2/2
✓ Branch 0 taken 15347431 times.
✓ Branch 1 taken 215550 times.
15562981 if(intbtn & INT_BTN_R) ret |= getInput(btnR, input_flags) ? INT_BTN_R : 0;
8922
2/2
✓ Branch 0 taken 15347431 times.
✓ Branch 1 taken 215550 times.
15562981 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, input_flags) ? INT_BTN_EX1 : 0;
8923
2/2
✓ Branch 0 taken 15347431 times.
✓ Branch 1 taken 215550 times.
15562981 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, input_flags) ? INT_BTN_EX2 : 0;
8924
2/2
✓ Branch 0 taken 15347431 times.
✓ Branch 1 taken 215550 times.
15562981 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, input_flags) ? INT_BTN_EX3 : 0;
8925
2/2
✓ Branch 0 taken 15347316 times.
✓ Branch 1 taken 215665 times.
15562981 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, input_flags) ? INT_BTN_EX4 : 0;
8926 15562981 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8927 }
8928
8929 7513 byte checkIntBtnVal(byte intbtn, byte vals)
8930 {
8931 7513 return intbtn&vals;
8932 }
8933
8934 219067 bool Up()
8935 {
8936 219067 return getInput(btnUp);
8937 }
8938 219066 bool Down()
8939 {
8940 219066 return getInput(btnDown);
8941 }
8942 219066 bool Left()
8943 {
8944 219066 return getInput(btnLeft);
8945 }
8946 219066 bool Right()
8947 {
8948 219066 return getInput(btnRight);
8949 }
8950 552983 bool cAbtn()
8951 {
8952 552983 return getInput(btnA);
8953 }
8954 3375311 bool cBbtn()
8955 {
8956 3375311 return getInput(btnB);
8957 }
8958 bool cSbtn()
8959 {
8960 return getInput(btnS);
8961 }
8962 218976 bool cLbtn()
8963 {
8964 218976 return getInput(btnL);
8965 }
8966 218976 bool cRbtn()
8967 {
8968 218976 return getInput(btnR);
8969 }
8970 bool cPbtn()
8971 {
8972 return getInput(btnP);
8973 }
8974 bool cEx1btn()
8975 {
8976 return getInput(btnEx1);
8977 }
8978 bool cEx2btn()
8979 {
8980 return getInput(btnEx2);
8981 }
8982 bool cEx3btn()
8983 {
8984 return getInput(btnEx3);
8985 }
8986 bool cEx4btn()
8987 {
8988 return getInput(btnEx4);
8989 }
8990 bool AxisUp()
8991 {
8992 return getInput(btnAxisUp);
8993 }
8994 bool AxisDown()
8995 {
8996 return getInput(btnAxisDown);
8997 }
8998 bool AxisLeft()
8999 {
9000 return getInput(btnAxisLeft);
9001 }
9002 bool AxisRight()
9003 {
9004 return getInput(btnAxisRight);
9005 }
9006
9007 bool cMbtn()
9008 {
9009 return getInput(btnM);
9010 }
9011 bool cF12()
9012 {
9013 return getInput(btnF12);
9014 }
9015 bool cF11()
9016 {
9017 return getInput(btnF11);
9018 }
9019 bool cF5()
9020 {
9021 return getInput(btnF5);
9022 }
9023 bool cQ()
9024 {
9025 return getInput(btnQ);
9026 }
9027 bool cI()
9028 {
9029 return getInput(btnI);
9030 }
9031
9032 219242 bool rUp()
9033 {
9034 219242 return getInput(btnUp, INPUT_PRESS);
9035 }
9036 218990 bool rDown()
9037 {
9038 218990 return getInput(btnDown, INPUT_PRESS);
9039 }
9040 218740 bool rLeft()
9041 {
9042 218740 return getInput(btnLeft, INPUT_PRESS);
9043 }
9044 217884 bool rRight()
9045 {
9046 217884 return getInput(btnRight, INPUT_PRESS);
9047 }
9048 4680 bool rAbtn()
9049 {
9050 4680 return getInput(btnA, INPUT_PRESS);
9051 }
9052 bool rBbtn()
9053 {
9054 return getInput(btnB, INPUT_PRESS);
9055 }
9056 218266 bool rSbtn()
9057 {
9058 218266 return getInput(btnS, INPUT_PRESS);
9059 }
9060 19229703 bool rMbtn()
9061 {
9062 19229703 return getInput(btnM, INPUT_PRESS);
9063 }
9064 186046 bool rLbtn()
9065 {
9066 186046 return getInput(btnL, INPUT_PRESS);
9067 }
9068 186041 bool rRbtn()
9069 {
9070 186041 return getInput(btnR, INPUT_PRESS);
9071 }
9072 218976 bool rPbtn()
9073 {
9074 218976 return getInput(btnP, INPUT_PRESS);
9075 }
9076 bool rEx1btn()
9077 {
9078 return getInput(btnEx1, INPUT_PRESS);
9079 }
9080 bool rEx2btn()
9081 {
9082 return getInput(btnEx2, INPUT_PRESS);
9083 }
9084 186037 bool rEx3btn()
9085 {
9086 186037 return getInput(btnEx3, INPUT_PRESS);
9087 }
9088 186037 bool rEx4btn()
9089 {
9090 186037 return getInput(btnEx4, INPUT_PRESS);
9091 }
9092 bool rAxisUp()
9093 {
9094 return getInput(btnAxisUp, INPUT_PRESS);
9095 }
9096 bool rAxisDown()
9097 {
9098 return getInput(btnAxisDown, INPUT_PRESS);
9099 }
9100 bool rAxisLeft()
9101 {
9102 return getInput(btnAxisLeft, INPUT_PRESS);
9103 }
9104 bool rAxisRight()
9105 {
9106 return getInput(btnAxisRight, INPUT_PRESS);
9107 }
9108
9109 bool rF11()
9110 {
9111 return getInput(btnF11, INPUT_PRESS);
9112 }
9113 bool rQ()
9114 {
9115 return getInput(btnQ, INPUT_PRESS);
9116 }
9117 bool rI()
9118 {
9119 return getInput(btnI, INPUT_PRESS);
9120 }
9121
9122 bool DrunkUp()
9123 {
9124 return getInput(btnUp, INPUT_DRUNK);
9125 }
9126 bool DrunkDown()
9127 {
9128 return getInput(btnDown, INPUT_DRUNK);
9129 }
9130 bool DrunkLeft()
9131 {
9132 return getInput(btnLeft, INPUT_DRUNK);
9133 }
9134 bool DrunkRight()
9135 {
9136 return getInput(btnRight, INPUT_DRUNK);
9137 }
9138 bool DrunkcAbtn()
9139 {
9140 return getInput(btnA, INPUT_DRUNK);
9141 }
9142 bool DrunkcBbtn()
9143 {
9144 return getInput(btnB, INPUT_DRUNK);
9145 }
9146 bool DrunkcEx1btn()
9147 {
9148 return getInput(btnEx1, INPUT_DRUNK);
9149 }
9150 bool DrunkcEx2btn()
9151 {
9152 return getInput(btnEx2, INPUT_DRUNK);
9153 }
9154 bool DrunkcSbtn()
9155 {
9156 return getInput(btnS, INPUT_DRUNK);
9157 }
9158 bool DrunkcMbtn()
9159 {
9160 return getInput(btnM, INPUT_DRUNK);
9161 }
9162 bool DrunkcLbtn()
9163 {
9164 return getInput(btnL, INPUT_DRUNK);
9165 }
9166 bool DrunkcRbtn()
9167 {
9168 return getInput(btnR, INPUT_DRUNK);
9169 }
9170 bool DrunkcPbtn()
9171 {
9172 return getInput(btnP, INPUT_DRUNK);
9173 }
9174
9175 bool DrunkrUp()
9176 {
9177 return getInput(btnUp, INPUT_PRESS | INPUT_DRUNK);
9178 }
9179 bool DrunkrDown()
9180 {
9181 return getInput(btnDown, INPUT_PRESS | INPUT_DRUNK);
9182 }
9183 bool DrunkrLeft()
9184 {
9185 return getInput(btnLeft, INPUT_PRESS | INPUT_DRUNK);
9186 }
9187 bool DrunkrRight()
9188 {
9189 return getInput(btnRight, INPUT_PRESS | INPUT_DRUNK);
9190 }
9191 bool DrunkrAbtn()
9192 {
9193 return getInput(btnA, INPUT_PRESS | INPUT_DRUNK);
9194 }
9195 bool DrunkrBbtn()
9196 {
9197 return getInput(btnB, INPUT_PRESS | INPUT_DRUNK);
9198 }
9199 bool DrunkrEx1btn()
9200 {
9201 return getInput(btnEx1, INPUT_PRESS | INPUT_DRUNK);
9202 }
9203 bool DrunkrEx2btn()
9204 {
9205 return getInput(btnEx2, INPUT_PRESS | INPUT_DRUNK);
9206 }
9207 bool DrunkrEx3btn()
9208 {
9209 return getInput(btnEx3, INPUT_PRESS | INPUT_DRUNK);
9210 }
9211 bool DrunkrEx4btn()
9212 {
9213 return getInput(btnEx4, INPUT_PRESS | INPUT_DRUNK);
9214 }
9215 bool DrunkrSbtn()
9216 {
9217 return getInput(btnS, INPUT_PRESS | INPUT_DRUNK);
9218 }
9219 bool DrunkrMbtn()
9220 {
9221 return getInput(btnM, INPUT_PRESS | INPUT_DRUNK);
9222 }
9223 bool DrunkrLbtn()
9224 {
9225 return getInput(btnL, INPUT_PRESS | INPUT_DRUNK);
9226 }
9227 bool DrunkrRbtn()
9228 {
9229 return getInput(btnR, INPUT_PRESS | INPUT_DRUNK);
9230 }
9231 bool DrunkrPbtn()
9232 {
9233 return getInput(btnP, INPUT_PRESS | INPUT_DRUNK);
9234 }
9235
9236 19269 void eat_buttons()
9237 {
9238 19269 getInput(btnA, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9239 19269 getInput(btnB, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9240 19269 getInput(btnS, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9241 19269 getInput(btnM, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9242 19269 getInput(btnL, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9243 19269 getInput(btnR, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9244 19269 getInput(btnP, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9245 19269 getInput(btnEx1, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9246 19269 getInput(btnEx2, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9247 19269 getInput(btnEx3, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9248 19269 getInput(btnEx4, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9249 19269 }
9250
9251 // Is true for the _first frame_ of a key press.
9252 // But! it is possible that a script manually sets the value of KeyPress,
9253 // in which case it will be restored to the "true" value based on `key_current_frame`
9254 // and `key_previous_frame` on the next frame.
9255 59 bool zc_readkey(int32_t k, bool ignoreDisable)
9256 {
9257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 if(ignoreDisable) return KeyPress[k];
9258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
59 switch(k)
9259 {
9260 case KEY_F7:
9261 case KEY_F8:
9262 case KEY_F9:
9263 return KeyPress[k];
9264
9265 default:
9266
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 12 times.
59 return KeyPress[k] && !disabledKeys[k];
9267 }
9268 59 }
9269
9270 // Is true for _every frame_ a key is held down.
9271 // But! it is possible that a script manually sets the value of KeyInput,
9272 // in which case it will be restored to the "true" value based on `key_current_frame`
9273 // on the next frame.
9274 bool zc_getkey(int32_t k, bool ignoreDisable)
9275 {
9276 if(ignoreDisable) return KeyInput[k];
9277 switch(k)
9278 {
9279 case KEY_F7:
9280 case KEY_F8:
9281 case KEY_F9:
9282 return KeyInput[k];
9283
9284 default:
9285 return KeyInput[k] && !disabledKeys[k];
9286 }
9287 }
9288
9289 // Reads (and then clears) the current frame key state directly.
9290 // Scripts can also modify `key_current_frame`.
9291 954 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9292 {
9293
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 950 times.
954 if(zc_getrawkey(k, ignoreDisable))
9294 {
9295 4 _key[k]=key[k]=key_current_frame[k]=0;
9296 4 return true;
9297 }
9298 950 _key[k]=key[k]=key_current_frame[k]=0;
9299 950 return false;
9300 954 }
9301
9302 // Reads the current frame key state directly.
9303 // Scripts can also modify `key_current_frame`.
9304 130182427 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9305 {
9306
2/2
✓ Branch 0 taken 110952606 times.
✓ Branch 1 taken 19229821 times.
130182427 if(ignoreDisable) return key_current_frame[k];
9307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19229821 times.
19229821 switch(k)
9308 {
9309 case KEY_F7:
9310 case KEY_F8:
9311 case KEY_F9:
9312 return key_current_frame[k];
9313
9314 default:
9315
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19229821 times.
19229821 return key_current_frame[k] && !disabledKeys[k];
9316 }
9317 130182427 }
9318
9319 // Only used for a handful of keys, like tilde and Function keys.
9320 // This state is never read within the game.
9321 // It exists so that all keyboard input still functions during replay,
9322 // without inadvertently doing things like toggling throttling if the player
9323 // presses ~
9324 bool zc_get_system_key(int32_t k)
9325 {
9326 return key_system[k];
9327 }
9328
9329 // True for the _first_ frame of a key press.
9330 173067327 bool zc_read_system_key(int32_t k)
9331 {
9332 173067327 return key_system_press[k];
9333 }
9334
9335 2442172281 bool is_system_key(int32_t k)
9336 {
9337
2/2
✓ Branch 0 taken 2269104954 times.
✓ Branch 1 taken 173067327 times.
2442172281 switch (k)
9338 {
9339 case KEY_BACKQUOTE:
9340 case KEY_CLOSEBRACE:
9341 case KEY_END:
9342 case KEY_HOME:
9343 case KEY_OPENBRACE:
9344 case KEY_PGDN:
9345 case KEY_PGUP:
9346 case KEY_TAB:
9347 case KEY_TILDE:
9348 173067327 return true;
9349 }
9350 2269104954 return is_Fkey(k);
9351 2442172281 }
9352
9353 19229703 void update_system_keys()
9354 {
9355
2/2
✓ Branch 0 taken 2442172281 times.
✓ Branch 1 taken 19229703 times.
2461401984 for (int32_t q = 0; q < 127; ++q)
9356 {
9357
2/2
✓ Branch 0 taken 403823763 times.
✓ Branch 1 taken 2038348518 times.
2442172281 if (!is_system_key(q))
9358 2038348518 continue;
9359
9360 403823763 key_system[q] = key[q];
9361
1/2
✓ Branch 0 taken 403823763 times.
✗ Branch 1 not taken.
403823763 key_system_press[q] = key_system[q] && !key_system_previous[q];
9362 403823763 key_system_previous[q] = key_system[q];
9363 403823763 }
9364 19229703 }
9365
9366 20569645 void update_keys()
9367 {
9368
2/2
✓ Branch 0 taken 2612344915 times.
✓ Branch 1 taken 20569645 times.
2632914560 for (int32_t q = 0; q < 127; ++q)
9369 {
9370 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9371
2/2
✓ Branch 0 taken 2612332215 times.
✓ Branch 1 taken 12700 times.
2612344915 if (!replay_is_replaying())
9372 12700 key_current_frame[q] = key[q];
9373
9374
2/2
✓ Branch 0 taken 2592244385 times.
✓ Branch 1 taken 20100530 times.
2612344915 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9375 2612344915 KeyInput[q] = key_current_frame[q];
9376 2612344915 key_previous_frame[q] = key_current_frame[q];
9377 2612344915 }
9378 20569645 }
9379
9380